From 6952cb9be013a41957e2bafbad329bfdb23f314b Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 11 Mar 2024 15:18:02 +0100 Subject: [PATCH] add ocamlformat --- .ocamlformat | 1 + lib/term.mli | 15 ++++++++++----- lib/type.mli | 2 +- lib/unification.mli | 1 - test/test_projet_pfa_23_24.ml | 25 +++++++++++++++++++------ 5 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 .ocamlformat diff --git a/.ocamlformat b/.ocamlformat new file mode 100644 index 0000000..0619e80 --- /dev/null +++ b/.ocamlformat @@ -0,0 +1 @@ +profile = janestreet diff --git a/lib/term.mli b/lib/term.mli index cc8da2a..2ae8515 100644 --- a/lib/term.mli +++ b/lib/term.mli @@ -2,11 +2,16 @@ This module contains the syntax of terms of a minimal programming language. *) type binop = - | Plus | Minus | Times | Div - [@@deriving eq, ord, show] + | Plus + | Minus + | Times + | Div +[@@deriving eq, ord, show] -type projection = First | Second - [@@deriving eq, ord, show] +type projection = + | First + | Second +[@@deriving eq, ord, show] (* Every value of type Term.t is the abstract syntax tree of a program. @@ -19,4 +24,4 @@ type t = | Proj of projection * t | Fun of Identifier.t * t | App of t * t - [@@deriving eq, ord, show] +[@@deriving eq, ord, show] diff --git a/lib/type.mli b/lib/type.mli index 16eef74..c3adb3d 100644 --- a/lib/type.mli +++ b/lib/type.mli @@ -3,4 +3,4 @@ type t = | Int | Product of t * t | Arrow of t * t - [@@deriving eq, ord, show] +[@@deriving eq, ord, show] diff --git a/lib/unification.mli b/lib/unification.mli index cc5bf9d..fca1f1a 100644 --- a/lib/unification.mli +++ b/lib/unification.mli @@ -5,6 +5,5 @@ You can use the slides on the Herbrand / Robinson algorithm to start designing your implementation. - *) val unify : Type.t -> Type.t -> TypeSubstitution.t option diff --git a/test/test_projet_pfa_23_24.ml b/test/test_projet_pfa_23_24.ml index c324194..0f9cd57 100644 --- a/test/test_projet_pfa_23_24.ml +++ b/test/test_projet_pfa_23_24.ml @@ -1,19 +1,32 @@ open TypeInference -let tests_typeof = (* TODO: add more tests *) +let tests_typeof = + (* TODO: add more tests *) let x = Identifier.fresh () in let y = Identifier.fresh () in - [ ("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)))); ] + [ "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))) ) + ] +;; let typeModule = (module Type : Alcotest.TESTABLE with type t = Type.t) let check_typeof term_text term expected_type = 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 open Alcotest in - run "Inference" [ - "typeof", List.map (fun (term_text, term, expected_type) -> check_typeof term_text term expected_type) tests_typeof ; + run + "Inference" + [ ( "typeof" + , List.map + (fun (term_text, term, expected_type) -> + check_typeof term_text term expected_type) + tests_typeof ) ] +;;