-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul of type annotations for generated OCaml code. Printing beta-…
…redexes as `match-with` expressions. Some cleanup of logging code.
- Loading branch information
Showing
18 changed files
with
546 additions
and
286 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
type num = int | ||
type _ place = | ||
| LocA : a place | ||
| LocB : b place | ||
and a | ||
|
||
and b | ||
|
||
type (_, | ||
_) nearby = | ||
| Here : (*∀'b.*)'b place * 'b place -> ('b, 'b) nearby | ||
| Transitive : (*∀'a, 'b, 'c.*)('a, 'b) nearby * ('b, 'c) nearby -> | ||
('a, 'c) nearby | ||
type boolean = | ||
| True : boolean | ||
| False : boolean | ||
let assert_boolean b = assert (b = True) | ||
external is_nearby : (('a, 'b) nearby -> boolean) = "is_nearby" | ||
type _ ex1 = | ||
| Ex1 : (*∀'a, 'b.*)('b place * ('a, 'b) nearby) -> 'a ex1 | ||
external wander : ('a place -> 'a ex1) = "wander" | ||
type (_, | ||
_) meet = | ||
| Same : (*∀'b.*) ('b, 'b) meet | ||
| NotSame : (*∀'a, 'b.*) ('a, 'b) meet | ||
external compare : ('a place -> 'b place -> ('a, 'b) meet) = "compare" | ||
let rec walk : type a b . (a place -> b place -> (a, b) nearby) = | ||
(fun x goal -> | ||
((match (compare x goal: (a, b) meet) with | ||
Same -> Here (x, goal) | ||
| NotSame -> | ||
let Ex1 ((y, to_y)) = wander x in Transitive (to_y, walk y goal)) : | ||
(a, b) nearby)) | ||
let () = assert_boolean (is_nearby (walk LocA LocB)); () | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
type num = int | ||
type _ term = | ||
| Lit : integer -> integer term | ||
| Plus : integer term * integer term -> integer term | ||
| IsZero : integer term -> boolean term | ||
| If : (*∀'a.*)boolean term * 'a term * 'a term -> 'a term | ||
| Pair : (*∀'a, 'b.*)'a term * 'b term -> (('a * 'b)) term | ||
| Fst : (*∀'a, 'b.*)(('a * 'b)) term -> 'a term | ||
| Snd : (*∀'a, 'b.*)(('a * 'b)) term -> 'b term | ||
and integer | ||
|
||
and boolean | ||
|
||
external plus : (integer -> integer -> integer) = "plus" | ||
external is_zero : (integer -> boolean) = "is_zero" | ||
external if_then : (boolean -> 'a -> 'a -> 'a) = "if_then" | ||
let rec eval : type a . (a term -> a) = | ||
((function Lit i -> i | IsZero x -> is_zero (eval x) | ||
| Plus (x, y) -> plus (eval x) (eval y) | ||
| If (b, t, e) -> if_then (eval b) (eval t) (eval e) | ||
| Pair (x, y) -> (eval x, eval y) | ||
| Fst p -> let ((x, y): (a * 't47)) = eval p in x | ||
| Snd p -> let ((x, y): ('t59 * a)) = eval p in y): a term -> a) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type num = int | ||
type _ term = | ||
| Lit : integer -> integer term | ||
| Plus : integer term * integer term -> integer term | ||
| IsZero : integer term -> boolean term | ||
| If : (*∀'a.*)boolean term * 'a term * 'a term -> 'a term | ||
and integer | ||
|
||
and boolean | ||
|
||
external plus : (integer -> integer -> integer) = "plus" | ||
external is_zero : (integer -> boolean) = "is_zero" | ||
external if_then : (boolean -> 'a -> 'a -> 'a) = "if_then" | ||
let rec eval : type a . (a term -> a) = | ||
((function Lit i -> i | IsZero x -> is_zero (eval x) | ||
| Plus (x, y) -> plus (eval x) (eval y) | ||
| If (b, t, e) -> if_then (eval b) (eval t) (eval e)): a term -> a) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.