mirror of
https://github.com/ProgramSnail/Lama.git
synced 2026-01-03 04:28:19 +00:00
Testing
This commit is contained in:
parent
4f040532b2
commit
0b6f64646b
10 changed files with 727 additions and 60 deletions
40
src/Embedding.ml
Normal file
40
src/Embedding.ml
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
(* A deep embedding of simple expressions in OCaml. *)
|
||||
|
||||
(* Opening GT yet again. *)
|
||||
open GT
|
||||
|
||||
(* Opening the substrate module for convenience. *)
|
||||
open Expr
|
||||
|
||||
(* Shortcuts for leaf constructors *)
|
||||
let ( ! ) x = Var x
|
||||
let ( !? ) n = Const n
|
||||
|
||||
(* Implementation of operators *)
|
||||
let binop op x y = Binop (op, x, y)
|
||||
|
||||
let ( + ) = binop "+"
|
||||
let ( - ) = binop "-"
|
||||
let ( * ) = binop "*"
|
||||
let ( / ) = binop "/"
|
||||
let ( % ) = binop "%"
|
||||
let ( < ) = binop "<"
|
||||
let ( <= ) = binop "<="
|
||||
let ( > ) = binop ">"
|
||||
let ( >= ) = binop ">="
|
||||
let ( == ) = binop "=="
|
||||
let ( != ) = binop "!="
|
||||
let ( && ) = binop "&&"
|
||||
let ( || ) = binop "!!"
|
||||
|
||||
(* Some predefined names for variables *)
|
||||
let x = !"x"
|
||||
let y = !"y"
|
||||
let z = !"z"
|
||||
let t = !"t"
|
||||
|
||||
(* Voila; comment this out before submitting the solution *)
|
||||
let _ =
|
||||
List.iter (fun e -> Printf.printf "eval s (%s) = %d\n" (show(expr) e) (eval s e)) [x+y*z- !?3; t-z+y && x]
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue