Skip to content

Commit

Permalink
add ott stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
palmskog committed Aug 31, 2023
1 parent f4d516e commit 0598907
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 4 deletions.
24 changes: 20 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1 class="title">Advanced Functional Programming Seminar Course</h1>
</div>

<h2 id="about-the-course">About the Course</h2>
<p>This seminar course focuses on the principles and practice of purely functional programming, using the <a href="https://cakeml.org">CakeML</a> language as an example.</p>
<p>This seminar course focuses on the principles and practice of purely functional programming. The course features the <a href="https://cakeml.org">CakeML</a> language and the <a href="https://github.com/ott-lang/ott">Ott tool</a> for defining languages and inductive relations.</p>

<h2 id="seminars-fall-2023">Seminars Fall 2023</h2>
<p>During fall 2023 period 1 at KTH, seminars will occur twice per week:</p>
Expand All @@ -47,13 +47,28 @@ <h2 id="seminar-slides">Seminar Slides</h2>
<tbody>
<tr class="odd">
<td align="left">1</td>
<td align="left">Functional languages, abstract syntax trees, variable binding, and inductive definitions</td>
<td align="left"><a href="seminars/sem1.pdf">slides</a>, <a href="http://www.cs.cmu.edu/~rwh/pfpl/abbrev.pdf">PFPL</a> chapters 1 and 2, <a href="https://lawrencecpaulson.github.io/papers/Aczel-Inductive-Defs.pdf">introduction to inductive definitions by Aczel</a></td>
<td align="left" width="50%">Functional languages, abstract syntax trees, variable binding, and inductive definitions</td>
<td align="left">
<ul>
<li><a href="seminars/sem1.pdf">slides</a></li>
<li><a href="http://www.cs.cmu.edu/~rwh/pfpl/abbrev.pdf">PFPL</a> chapters 1 and 2</li>
<li><a href="https://lawrencecpaulson.github.io/papers/Aczel-Inductive-Defs.pdf">introduction to inductive definitions</a></li>
<li><a href="ott/functional.ott">small functional language Ott file</a></li>
<li><a href="ott/functional.pdf">small functional language pdf</a></li>
</ul>
</td>
</tr>
<tr class="even">
<td align="left">2</td>
<td align="left">Untyped lambda calculus, operational semantics, combinators, encodings</td>
<td align="left"><a href="seminars/sem2.pdf">slides</a>, <a href="http://www.cs.cmu.edu/~rwh/pfpl/supplements/ulc.pdf">supplement by Harper</a></td>
<td align="left">
<ul>
<li><a href="seminars/sem2.pdf">slides</a></li>
<li><a href="http://www.cs.cmu.edu/~rwh/pfpl/supplements/ulc.pdf">supplement by Harper</a></li>
<li><a href="ott/lam.ott">lambda calculus Ott file</a></li>
<li><a href="ott/lam.pdf">lambda calculus pdf</a></li>
</ul>
</td>
</tr>
<tr class="odd">
<td align="left">3</td>
Expand Down Expand Up @@ -125,6 +140,7 @@ <h2 id="homework">Homework</h2>
<h2 id="resources">Resources</h2>
<ul>
<li><a href="https://www.cs.cmu.edu/~rwh/pfpl/">Practical Foundations of Programming Languages</a> (main course book, <a href="http://www.cs.cmu.edu/~rwh/pfpl/abbrev.pdf">abbreviated pdf</a>)</li>
<li><a href="https://github.com/ott-lang/ott">Ott tool for defining languages and inductive relations</a></li>
</ul>
</body>
</html>
112 changes: 112 additions & 0 deletions ott/functional.ott
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
embed
{{ coq
Require Export Ascii.
Require Export String.

Hint Resolve ascii_dec : ott_coq_equality.
}}
metavar n ::=
{{ lex numeral }}
{{ coq nat }}
{{ coq-equality }}
{{ com number }}
metavar x ::=
{{ lex alphanum }}
{{ coq string }}
{{ coq-equality }}
{{ com variable }}
grammar
e :: e_ ::=
| x :: :: var {{ com variable }}
| n :: :: num {{ com number }}
| e + e' :: :: plus {{ com plus }}
| e * e' :: :: times {{ com times }}
| let x := e in e' :: :: def (+ bind x in e' +)
{{ com let }}
| e [ e' / x ] :: M :: subst
{{ com substitution }}
{{ coq (subst_e [[e']] [[x]] [[e]]) }}
| ( e ) :: S :: parentheses
{{ coq ([[e]]) }}

terminals :: terminals_ ::=
| -> :: :: red
{{ tex \rightarrow }}
| \||/ :: :: down
{{ tex \Downarrow }}

formula :: formula_ ::=
{{ com formulas }}
| judgement :: :: judgement
| n + n' = n'' :: M :: num_plus_eq
{{ coq ([[n]] + [[n']] = [[n'']]) }}
| n * n' = n'' :: M :: num_times_eq
{{ coq ([[n]] * [[n']] = [[n'']]) }}

substitutions
single e x :: subst

%freevars
% e x :: free

defns
operational_semantics :: os_ ::=

defn
e -> e' :: :: red :: red_
{{ com reduction step }} by

n1 + n2 = n
------------ :: plus
n1 + n2 -> n

e1 -> e'1
------------------- :: plus_l
e1 + e2 -> e'1 + e2

e -> e'
--------------- :: plus_r
n + e -> n + e'

n1 * n2 = n
------------ :: times
n1 * n2 -> n

e1 -> e'1
------------------- :: times_l
e1 * e2 -> e'1 * e2

e -> e'
--------------- :: times_r
n * e -> n * e'

e1 -> e'1
--------------------------------------- :: let
let x := e1 in e2 -> let x := e'1 in e2

-------------------------------- :: bind
let x := n in e2 -> e2 [ n / x ]

defn
e \||/ n :: :: eval :: eval_
{{ com evaluates to }} by

-------- :: num
n \||/ n

e1 \||/ n1
e2 \||/ n2
n1 + n2 = n
-------------- :: plus
e1 + e2 \||/ n

e1 \||/ n1
e2 \||/ n2
n1 * n2 = n
-------------- :: times
e1 * e2 \||/ n

e1 \||/ n1
e2 [ n1 / x ] \||/ n2
------------------------- :: let
let x := e1 in e2 \||/ n2
Binary file added ott/functional.pdf
Binary file not shown.
130 changes: 130 additions & 0 deletions ott/lam.ott
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
% all
metavar termvar, x, y ::= {{ com term variable }}
{{ isa string}} {{ coq nat}} {{ hol string}} {{ coq-equality }}
{{ ocaml int}} {{ lex alphanum}} {{ tex \mathit{[[termvar]]} }}

grammar
t :: 't_' ::= {{ com term }}
| x :: :: Var {{ com variable}}
| \ x . t :: :: Lam (+ bind x in t +) {{ com lambda }}
| t t' :: :: App {{ com app }}
| ( t ) :: S:: Paren {{ icho [[t]] }}
| [ t / x ] t' :: M:: Tsub
{{ icho (tsubst_t [[t]] [[x]] [[t']])}}

v :: 'v_' ::= {{ com value }}
| \ x . t :: :: Lam {{ com lambda }}

terminals :: 'terminals_' ::=
| \ :: :: lambda {{ tex \lambda }}
| --> :: :: red {{ tex \longrightarrow }}
| in :: :: in {{ tex \in }}
| <> :: :: neq {{ tex \neq }}
| =a :: :: eqa {{ tex \equiv_\alpha }}
| =b :: :: eqb {{ tex \equiv_\beta }}
| FV :: :: FV {{ tex \mathrm{FV} }}
| notin :: :: notin {{ tex \notin }}

formula :: formula_ ::=
{{ com formulas }}
| judgement :: :: judgement
| x <> x' :: M :: var_neq
| x notin FV(t) :: M :: notin_fv

subrules
v <:: t

substitutions
single t x :: tsubst

defns
Jop :: '' ::=

defn
t1 --> t2 :: ::reduce::'' {{ com $[[t1]]$ reduces to $[[t2]]$}} by


-------------------------- :: ax_app
(\x.t12) v2 --> [v2/x]t12

t1 --> t1'
-------------- :: ctx_app_fun
t1 t --> t1' t

t1 --> t1'
-------------- :: ctx_app_arg
v t1 --> v t1'

defn
x in FV ( t ) :: :: fv ::'' {{ com free variable }} by

---------- :: var
x in FV(x)

x in FV(t1)
-------------- :: app_l
x in FV(t1 t2)

x in FV(t2)
-------------- :: app_r
x in FV(t1 t2)

x in FV(t)
x <> y
------------- :: lam
x in FV(\y.t)

defn
t =a t' :: :: aeq :: aeq_ {{ com alpha equivalence }} by

------ :: id
t =a t

t =a t'
------- :: sym
t' =a t

t =a t'
t' =a t''
--------- :: trans
t =a t''

t1 =a t1'
t2 =a t2'
---------------- :: app
t1 t2 =a t1' t2'

t =a t'
------------- :: lam
\x.t =a \x.t'

x' notin FV(t)
------------------- :: subst
\x.t =a \x'.[x'/x]t

defn
t =b t' :: :: beq :: beq_ {{ com beta equivalence }} by

------ :: id
t =b t

t =b t'
------- :: sym
t' =b t

t =b t'
t' =b t''
--------- :: trans
t =b t''

t1 =b t1'
t2 =b t2'
--------- :: app
t1 t2 =b t1' t2'

t =b t'
------------- :: lam
\x.t =b \x.t'

--------------------- :: subst
(\x.t) t' =b [t'/x] t
Binary file added ott/lam.pdf
Binary file not shown.

0 comments on commit 0598907

Please sign in to comment.