-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type aliasing
ListInt = Lis Int;
does not produce an (eval) error a…
…nymore * tests/eval_test.ml: Added test for type aliasing * src/env.ml: Added a `Vinductive` value to detect type aliasing calls * src/eval.ml: type aliasing calls to constructor are recognized and not evaluated * src/REPL.ml: file provided using the command line are read in the correct order * samples/typer_proof.typer: Added a new example `samples/typer_proof.typer` which implements a Tree based interpreter and a Stack VM.
- Loading branch information
Showing
7 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
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,78 @@ | ||
% Example from `An Introduction to programming and proving with Dependent Types in Coq` | ||
% http://adam.chlipala.net/cpdt/ | ||
% | ||
% | ||
|
||
type OperatorType | ||
| Plus | ||
| Times; | ||
|
||
Exp : Type; | ||
type Exp | ||
| Const Int | ||
| BinaryNode OperatorType Exp Exp; | ||
|
||
% retrieve function from OperatorType | ||
binopDenote : OperatorType -> Int -> Int -> Int; | ||
binopDenote b = | ||
case b | ||
| Plus => _+_ | ||
| Times => _*_; | ||
|
||
|
||
% Tree based interpreter | ||
expDenote : Exp -> Int; | ||
expDenote e = | ||
case e | ||
| Const n => n | ||
| BinaryNode op lhs rhs => | ||
(binopDenote op) (expDenote lhs) (expDenote rhs); | ||
|
||
% Create a Stack based VM | ||
% ----------------------- | ||
|
||
% Instruction set | ||
type Instr | ||
| IConst Int | ||
| IBinop OperatorType; | ||
|
||
% Type alias | ||
Program = List Instr; | ||
Stack = List Int; | ||
|
||
% eval instruction | ||
instrDenote : Instr -> Stack -> Option Stack; | ||
instrDenote i s = | ||
case i | ||
| IConst n => some (cons n s) | ||
| IBinop b => | ||
(case s | ||
| cons arg1 s' => (case s' | ||
| cons arg2 s'' => some | ||
(cons ((binopDenote b) arg1 arg2) s'') | ||
| _ => none) | ||
| _ => none); | ||
|
||
% eval program | ||
progDenote : Program -> Stack -> Option Stack; | ||
progDenote p s = | ||
case p | ||
| nil => some s | ||
| cons i p' => (case instrDenote i s | ||
| none => none | ||
| some s' => progDenote p' s'); | ||
|
||
% Compile expression to Program | ||
compile : Exp -> Program; | ||
compile e = | ||
case e | ||
| Const n => cons (IConst n) nil | ||
| BinaryNode b lhs rhs => | ||
concat (compile rhs) (concat (compile lhs) (cons (IBinop b) nil)); | ||
|
||
% Make a proof that our VM is behaving like our interpreter | ||
% --------------------------------------------------------- | ||
|
||
% Stack VM == Interpreter | ||
% progDenote (compile e) nil == some (expDenote (cons e nil)) | ||
|
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