add ocamlformat
This commit is contained in:
parent
e942f30703
commit
6952cb9be0
5 changed files with 31 additions and 13 deletions
1
.ocamlformat
Normal file
1
.ocamlformat
Normal file
|
@ -0,0 +1 @@
|
||||||
|
profile = janestreet
|
|
@ -2,10 +2,15 @@
|
||||||
This module contains the syntax of terms of a minimal programming language.
|
This module contains the syntax of terms of a minimal programming language.
|
||||||
*)
|
*)
|
||||||
type binop =
|
type binop =
|
||||||
| Plus | Minus | Times | Div
|
| Plus
|
||||||
|
| Minus
|
||||||
|
| Times
|
||||||
|
| Div
|
||||||
[@@deriving eq, ord, show]
|
[@@deriving eq, ord, show]
|
||||||
|
|
||||||
type projection = First | Second
|
type projection =
|
||||||
|
| First
|
||||||
|
| Second
|
||||||
[@@deriving eq, ord, show]
|
[@@deriving eq, ord, show]
|
||||||
|
|
||||||
(*
|
(*
|
||||||
|
|
|
@ -5,6 +5,5 @@
|
||||||
|
|
||||||
You can use the slides on the Herbrand / Robinson algorithm
|
You can use the slides on the Herbrand / Robinson algorithm
|
||||||
to start designing your implementation.
|
to start designing your implementation.
|
||||||
|
|
||||||
*)
|
*)
|
||||||
val unify : Type.t -> Type.t -> TypeSubstitution.t option
|
val unify : Type.t -> Type.t -> TypeSubstitution.t option
|
||||||
|
|
|
@ -1,19 +1,32 @@
|
||||||
open TypeInference
|
open TypeInference
|
||||||
|
|
||||||
let tests_typeof = (* TODO: add more tests *)
|
let tests_typeof =
|
||||||
|
(* TODO: add more tests *)
|
||||||
let x = Identifier.fresh () in
|
let x = Identifier.fresh () in
|
||||||
let y = Identifier.fresh () in
|
let y = Identifier.fresh () in
|
||||||
[ ("0", Term.IntConst 0, Some Type.Int);
|
[ "0", Term.IntConst 0, Some Type.Int
|
||||||
("fun x -> fun y -> x+y", Term.(Fun (x, Fun (y, Binop (Var x, Plus, Var y)))), Some Type.(Arrow (Int, Arrow (Int, Int)))); ]
|
; ( "fun x -> fun y -> x+y"
|
||||||
|
, Term.(Fun (x, Fun (y, Binop (Var x, Plus, Var y))))
|
||||||
|
, Some Type.(Arrow (Int, Arrow (Int, Int))) )
|
||||||
|
]
|
||||||
|
;;
|
||||||
|
|
||||||
let typeModule = (module Type : Alcotest.TESTABLE with type t = Type.t)
|
let typeModule = (module Type : Alcotest.TESTABLE with type t = Type.t)
|
||||||
|
|
||||||
let check_typeof term_text term expected_type =
|
let check_typeof term_text term expected_type =
|
||||||
let open Alcotest in
|
let open Alcotest in
|
||||||
test_case term_text `Quick (fun () -> check (option typeModule) "Same type" expected_type (Inference.typeof term))
|
test_case term_text `Quick (fun () ->
|
||||||
|
check (option typeModule) "Same type" expected_type (Inference.typeof term))
|
||||||
|
;;
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
let open Alcotest in
|
let open Alcotest in
|
||||||
run "Inference" [
|
run
|
||||||
"typeof", List.map (fun (term_text, term, expected_type) -> check_typeof term_text term expected_type) tests_typeof ;
|
"Inference"
|
||||||
|
[ ( "typeof"
|
||||||
|
, List.map
|
||||||
|
(fun (term_text, term, expected_type) ->
|
||||||
|
check_typeof term_text term expected_type)
|
||||||
|
tests_typeof )
|
||||||
]
|
]
|
||||||
|
;;
|
||||||
|
|
Reference in a new issue