Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file test_builder.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348openFmlibopenAlba_coreopenBuild_expressionmodulePretty_printer=Pretty_printer.Pretty(String_printer)moduleTerm_print=Context.Pretty(Pretty_printer)moduleExpression=Ast.ExpressionmoduleExpression_parser=Parser_lang.Make(Expression)moduleError_print=Build_problem.Print(Pretty_printer)letstandard_context:Context.t=Standard_context.make()letstring_of_term_type(term:Term.t)(typ:Term.t):string=String_printer.run(Pretty_printer.run07070(Term_print.print(Term.Typed(term,typ))standard_context))let_=string_of_term_typeletstring_of_description(descr:Build_problem.description):string=String_printer.run(Pretty_printer.run07070(Error_print.descriptiondescr))let_=string_of_descriptionletbuild_expression(str:string):(Term.t*Term.typ,Build_problem.t)result=letopenExpression_parserinletp=run(expression())strinassert(has_endedp);assert(has_succeededp);buildOption.(value(resultp))standard_contextlet%test_=matchbuild_expression"Proposition"with|Ok(term,typ)->string_of_term_typetermtyp="Proposition: Any"|_->falselet%test_=matchbuild_expression"Any"with|Ok(term,typ)->string_of_term_typetermtyp="Any: Any(1)"|_->falselet%test_=matchbuild_expression"Int"with|Ok(term,typ)->string_of_term_typetermtyp="Int: Any"|_->falselet%test_=matchbuild_expression"abc"with|Error(_,No_name)->true|_->falselet%test_=matchbuild_expression"Int -> all (B: Any): (Int -> B) -> B"with|Ok(term,typ)->string_of_term_typetermtyp="Int -> (all (B: Any): (Int -> B) -> B): Any(1)"|_->falselet%test_=matchbuild_expression"identity"with|Ok(term,typ)->string_of_term_typetermtyp="identity: all (A: Any): A -> A"|_->falselet%test_=matchbuild_expression"identity: Int -> Int"with|Ok(term,typ)->string_of_term_typetermtyp="(identity: Int -> Int): Int -> Int"|_->falselet%test_=matchbuild_expression"Int -> String: Proposition"with|Error(_,Wrong_type_)->true|_->falselet%test_=lettp_str="(Character -> String) -> String"inmatchbuild_expression("(|>) 'a': "^tp_str)with|Ok(term,typ)->string_of_term_typetermtyp="((|>) 'a': "^tp_str^"):\n "^tp_str|_->falselet%test_=matchbuild_expression"all a b: a = b"with|Error(_,Cannot_infer_bound)->true|_->falselet%test_=matchbuild_expression"all a b: 'x' = b"with|Error(_,Cannot_infer_bound)->true|_->falselet%test_=matchbuild_expression"all a (b: Int): a = b"with|Ok(term,typ)->string_of_term_typetermtyp="(all a (b: Int): a = b): Proposition"|_->falselet%test_=matchbuild_expression"(|>) \"A\" (+) \"a\""with|Ok(term,typ)->string_of_term_typetermtyp="(|>) \"A\" (+) \"a\": String"|_->falselet%test_=matchbuild_expression"1 |> (+) 2"with|Ok(term,typ)->string_of_term_typetermtyp="1 |> (+) 2: Int"|_->falselet%test_=matchbuild_expression"'a'= 'b' "with|Ok(term,typ)->string_of_term_typetermtyp="'a' = 'b': Proposition"|_->falselet%test_=matchbuild_expression"1 + 2"with|Ok(term,typ)->string_of_term_typetermtyp="1 + 2: Int"|_->falselet%test_=matchbuild_expression"all x: x + 2 = 3"with|Ok(term,typ)->string_of_term_typetermtyp="(all x: x + 2 = 3): Proposition"|_->falselet%test_=matchbuild_expression"(\\x := x + 2) 1"with|Ok(term,typ)->string_of_term_typetermtyp="(\\ x := x + 2) 1: Int"|_->falselet%test_=matchbuild_expression"(\\x f := f x) 1 ((+) 2)"with|Ok(term,typ)->string_of_term_typetermtyp="(\\ x f := f x) 1 ((+) 2): Int"|_->falselet%test_=matchbuild_expression"(\\x y f := f x y) 1 2 (+)"with|Ok(term,typ)->string_of_term_typetermtyp="(\\ x y f := f x y) 1 2 (+): Int"|_->falselet%test_=matchbuild_expression"\\ x y := x = y"with|Error(_,Cannot_infer_bound)->true|_->falselet%test_=matchbuild_expression"(+) 1 2 3"with|Error(_,Not_a_function_)->true|_->falselet%test_=matchbuild_expression"1 + a + b where\
\n a := 8\
\n b := 10"with|Ok(term,typ)->string_of_term_typetermtyp="(1 + a + b where a := 8; b := 10): Int"|_->falselet%test_=matchbuild_expression"1234567890 + f 12345677890 where\
\n f x := 20002000 + g x\
\n g x := 1234567890 * x"with|Ok(term,typ)->string_of_term_typetermtyp="(1234567890 + f 12345677890 where\
\n f x := 20002000 + g x\
\n g x := 1234567890 * x):\
\n Int"|_->false(* Ambiguous Expressions *)let%test_=matchbuild_expression"(+)"with|Error(_,Ambiguous_)->true|_->falselet%test_=matchbuild_expression"\\ x y := x + y"with|Error(_,Ambiguous_)->true|_->false(* Propositions *)let%test_=matchbuild_expression"\\a := p: a => a where p x := x"with|Ok_->true|Error(_,description)->Printf.printf"%s\n"(string_of_descriptiondescription);falselet%test_=matchbuild_expression"\\a: a => a := identity"with|Ok_->true|Error(_,description)->Printf.printf"%s\n"(string_of_descriptiondescription);falselet%test_=matchbuild_expression"\\a b: a => b => a := \\ x y := x"with|Ok_->true|Error(_,description)->Printf.printf"%s\n"(string_of_descriptiondescription);false