Removing lines with more than 80 characters in tests
This commit is contained in:
@ -35,7 +35,8 @@ let program =
|
|||||||
LetIn
|
LetIn
|
||||||
("f",
|
("f",
|
||||||
(Function ("x",
|
(Function ("x",
|
||||||
FunctionType (IntegerType, FunctionType (IntegerType, IntegerType)),
|
FunctionType
|
||||||
|
(IntegerType, FunctionType (IntegerType, IntegerType)),
|
||||||
(Function ("y", FunctionType (IntegerType, IntegerType),
|
(Function ("y", FunctionType (IntegerType, IntegerType),
|
||||||
Plus (Variable "x", Variable "y"))
|
Plus (Variable "x", Variable "y"))
|
||||||
)
|
)
|
||||||
@ -73,10 +74,13 @@ let program =
|
|||||||
("f",
|
("f",
|
||||||
(Function (
|
(Function (
|
||||||
"z",
|
"z",
|
||||||
FunctionType (FunctionType (IntegerType, IntegerType), IntegerType),
|
FunctionType (FunctionType (IntegerType, IntegerType),
|
||||||
|
FunctionType (FunctionType (IntegerType, IntegerType),
|
||||||
|
FunctionType (IntegerType, IntegerType))),
|
||||||
(Function (
|
(Function (
|
||||||
"y",
|
"y",
|
||||||
FunctionType (FunctionType (IntegerType, IntegerType), IntegerType),
|
FunctionType (FunctionType (IntegerType, IntegerType),
|
||||||
|
FunctionType (IntegerType, IntegerType)),
|
||||||
Function (
|
Function (
|
||||||
"x",
|
"x",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
@ -91,10 +95,12 @@ let program =
|
|||||||
(
|
(
|
||||||
(Application
|
(Application
|
||||||
(Variable "f",
|
(Variable "f",
|
||||||
Function ("x", FunctionType (IntegerType, IntegerType), Plus (Variable "x", Integer 1))
|
Function ("x", FunctionType (IntegerType, IntegerType),
|
||||||
|
Plus (Variable "x", Integer 1))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Function ("x", FunctionType (IntegerType, IntegerType), Minus (Variable "x", Integer 1))
|
Function ("x", FunctionType (IntegerType, IntegerType),
|
||||||
|
Minus (Variable "x", Integer 1))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -115,7 +121,13 @@ let program =
|
|||||||
("f",
|
("f",
|
||||||
"x",
|
"x",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
(IfThenElse (CmpLess (Variable "x", Integer 2),Integer 1, Plus (Variable "x", Application (Variable "f", Minus (Variable "x", Integer 1))))),
|
(IfThenElse (CmpLess (Variable "x", Integer 2),
|
||||||
|
Integer 1,
|
||||||
|
Plus (
|
||||||
|
Variable "x",
|
||||||
|
Application (
|
||||||
|
Variable "f",
|
||||||
|
Minus (Variable "x", Integer 1))))),
|
||||||
(Variable "f")
|
(Variable "f")
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
@ -129,7 +141,9 @@ match reduce program 10 with
|
|||||||
let program =
|
let program =
|
||||||
LetIn
|
LetIn
|
||||||
("f",
|
("f",
|
||||||
(LetIn ("a", Integer 1, (Function ("y", FunctionType (IntegerType, IntegerType), Plus (Variable "y", Variable "a"))))),
|
(LetIn ("a", Integer 1, (Function ("y",
|
||||||
|
FunctionType (IntegerType, IntegerType),
|
||||||
|
Plus (Variable "y", Variable "a"))))),
|
||||||
(LetIn ("a", Integer 2, Variable "f"))
|
(LetIn ("a", Integer 2, Variable "f"))
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
@ -145,7 +159,11 @@ let program =
|
|||||||
"f",
|
"f",
|
||||||
"x",
|
"x",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
(IfThenElse (CmpLessEq (Variable "x", Integer 0), Integer 1, Times (Variable "x", Application (Variable "f", Minus (Variable "x", Integer 1))))),
|
(IfThenElse (CmpLessEq (Variable "x", Integer 0),
|
||||||
|
Integer 1,
|
||||||
|
Times (Variable "x",
|
||||||
|
Application (Variable "f",
|
||||||
|
Minus (Variable "x", Integer 1))))),
|
||||||
(Variable "f")
|
(Variable "f")
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
@ -158,27 +176,38 @@ match reduce program 10 with
|
|||||||
(* Hailstone sequence's lenght program *)
|
(* Hailstone sequence's lenght program *)
|
||||||
|
|
||||||
let program =
|
let program =
|
||||||
|
|
||||||
LetFun (
|
LetFun (
|
||||||
"collatz",
|
"collatz",
|
||||||
"input",
|
"input",
|
||||||
FunctionType (TupleType (IntegerType, IntegerType), IntegerType),
|
FunctionType (TupleType (IntegerType, IntegerType), IntegerType),
|
||||||
(
|
(
|
||||||
IfThenElse (BNot (Cmp (First (Variable "input"), Integer 1)),
|
IfThenElse (BNot (Cmp (First (Variable "input"), Integer 1)),
|
||||||
(IfThenElse (Cmp (Modulo (First (Variable "input"), Integer 2), Integer 0),
|
(IfThenElse (Cmp (Modulo (First (Variable "input"),
|
||||||
|
Integer 2),
|
||||||
|
Integer 0),
|
||||||
Application (Variable "collatz",
|
Application (Variable "collatz",
|
||||||
Tuple (
|
Tuple (
|
||||||
Division (First (Variable "input"), Integer 2),
|
Division (First
|
||||||
Plus (Integer 1, Second (Variable "input")))),
|
(Variable "input"),
|
||||||
|
Integer 2),
|
||||||
|
Plus (Integer 1, Second
|
||||||
|
(Variable "input")))),
|
||||||
Application (Variable "collatz",
|
Application (Variable "collatz",
|
||||||
Tuple (
|
Tuple (
|
||||||
Plus (Integer 1, Times (Integer 3, First (Variable "input"))),
|
Plus
|
||||||
Plus (Integer 1, Second (Variable "input")))))),
|
(Integer 1,
|
||||||
|
Times
|
||||||
|
(Integer 3,
|
||||||
|
First (Variable "input"))),
|
||||||
|
Plus (
|
||||||
|
Integer 1,
|
||||||
|
Second (Variable "input")))))),
|
||||||
(Second (Variable "input")))
|
(Second (Variable "input")))
|
||||||
),
|
),
|
||||||
(Function ("x",
|
(Function ("x",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
Application (Variable "collatz", Tuple (Variable "x", Integer 1))))
|
Application (Variable "collatz",
|
||||||
|
Tuple (Variable "x", Integer 1))))
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@ -194,11 +223,15 @@ let program =
|
|||||||
"sum",
|
"sum",
|
||||||
"n",
|
"n",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
(IfThenElse ((BOr (Cmp (Modulo (Variable "n", Integer 3), Integer 0), Cmp (Modulo (Variable "n", Integer 5), Integer 0))),
|
(IfThenElse ((BOr (Cmp (Modulo (Variable "n", Integer 3), Integer 0),
|
||||||
Plus (Variable "n", Application (Variable "sum", Minus (Variable "n", Integer 1))),
|
Cmp (Modulo (Variable "n", Integer 5), Integer 0))),
|
||||||
|
Plus (Variable "n",
|
||||||
|
Application (Variable "sum",
|
||||||
|
Minus (Variable "n", Integer 1))),
|
||||||
(IfThenElse ((CmpLessEq (Variable "n", Integer 1)),
|
(IfThenElse ((CmpLessEq (Variable "n", Integer 1)),
|
||||||
(Integer 0),
|
(Integer 0),
|
||||||
(Application (Variable "sum", Minus (Variable "n", Integer 1))))
|
(Application (Variable "sum",
|
||||||
|
Minus (Variable "n", Integer 1))))
|
||||||
))
|
))
|
||||||
),
|
),
|
||||||
(Variable "sum")
|
(Variable "sum")
|
||||||
@ -231,7 +264,8 @@ let program =
|
|||||||
LetFun (
|
LetFun (
|
||||||
"fib",
|
"fib",
|
||||||
"i",
|
"i",
|
||||||
FunctionType (IntegerType, FunctionType (IntegerType, FunctionType (IntegerType, IntegerType))),
|
FunctionType (IntegerType, FunctionType
|
||||||
|
(IntegerType, FunctionType (IntegerType, IntegerType))),
|
||||||
Function (
|
Function (
|
||||||
"a",
|
"a",
|
||||||
FunctionType (IntegerType, FunctionType (IntegerType, IntegerType)),
|
FunctionType (IntegerType, FunctionType (IntegerType, IntegerType)),
|
||||||
|
|||||||
@ -27,7 +27,8 @@ let program =
|
|||||||
(Sequence (
|
(Sequence (
|
||||||
(Assignment ("x", (Integer 1))),
|
(Assignment ("x", (Integer 1))),
|
||||||
(Assignment ("b",
|
(Assignment ("b",
|
||||||
(Plus ((Plus (Variable "a", Variable "x")), (Variable "y")))))
|
(Plus ((Plus (Variable "a", Variable "x")),
|
||||||
|
(Variable "y")))))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -83,7 +84,8 @@ let program =
|
|||||||
(Assignment ("b", (Plus (Variable "b", Integer 1)))),
|
(Assignment ("b", (Plus (Variable "b", Integer 1)))),
|
||||||
(If (
|
(If (
|
||||||
(BCmp (Modulo (Variable "a", Integer 2), Integer 1)),
|
(BCmp (Modulo (Variable "a", Integer 2), Integer 1)),
|
||||||
(Assignment ("a", Plus (Times (Integer 3, Variable "a"), Integer 1))),
|
(Assignment ("a", Plus (Times (Integer 3, Variable "a"),
|
||||||
|
Integer 1))),
|
||||||
(Assignment ("a", Division (Variable "a", Integer 2)))
|
(Assignment ("a", Division (Variable "a", Integer 2)))
|
||||||
))
|
))
|
||||||
))
|
))
|
||||||
@ -161,7 +163,8 @@ let program =
|
|||||||
(BCmpGreater (Variable "n", Integer 1)),
|
(BCmpGreater (Variable "n", Integer 1)),
|
||||||
(Sequence (
|
(Sequence (
|
||||||
(Sequence (
|
(Sequence (
|
||||||
(Assignment ("tmp", Plus (Variable "fnow", Variable "fnext"))),
|
(Assignment ("tmp", Plus (Variable "fnow",
|
||||||
|
Variable "fnext"))),
|
||||||
(Assignment ("fnow", Variable "fnext"))
|
(Assignment ("fnow", Variable "fnext"))
|
||||||
)),
|
)),
|
||||||
(Sequence (
|
(Sequence (
|
||||||
@ -205,15 +208,21 @@ let program =
|
|||||||
))
|
))
|
||||||
)),
|
)),
|
||||||
(Sequence (
|
(Sequence (
|
||||||
(Assignment ("d", Division (Minus (Variable "n", Integer 1), Power (Integer 2, Variable "s")))),
|
(Assignment ("d", Division (Minus (Variable "n", Integer 1),
|
||||||
|
Power (Integer 2, Variable "s")))),
|
||||||
(For (
|
(For (
|
||||||
(Assignment ("i", Integer 20)),
|
(Assignment ("i", Integer 20)),
|
||||||
(BCmpGreater (Variable "i", Integer 0)),
|
(BCmpGreater (Variable "i", Integer 0)),
|
||||||
(Assignment ("i", Minus (Variable "i", Integer 1))),
|
(Assignment ("i", Minus (Variable "i", Integer 1))),
|
||||||
(Sequence (
|
(Sequence (
|
||||||
Sequence (
|
Sequence (
|
||||||
(Assignment ("a", Plus (Rand (Minus (Variable "n", Integer 4)), Integer 2))),
|
(Assignment
|
||||||
(Assignment ("x", PowerMod (Variable "a", Variable "d", Variable "n")))),
|
("a",
|
||||||
|
Plus (Rand (Minus (Variable "n", Integer 4)),
|
||||||
|
Integer 2))),
|
||||||
|
(Assignment ("x", PowerMod (Variable "a",
|
||||||
|
Variable "d",
|
||||||
|
Variable "n")))),
|
||||||
Sequence (
|
Sequence (
|
||||||
(For (
|
(For (
|
||||||
(Assignment ("j", Integer 0)),
|
(Assignment ("j", Integer 0)),
|
||||||
@ -221,9 +230,17 @@ let program =
|
|||||||
(Assignment ("j", Plus (Variable "j", Integer 1))),
|
(Assignment ("j", Plus (Variable "j", Integer 1))),
|
||||||
(Sequence (
|
(Sequence (
|
||||||
Sequence (
|
Sequence (
|
||||||
(Assignment ("y", PowerMod (Variable "x", Integer 2, Variable "n"))),
|
(Assignment ("y", PowerMod (Variable "x",
|
||||||
|
Integer 2,
|
||||||
|
Variable "n"))),
|
||||||
(If (
|
(If (
|
||||||
(BAnd (BAnd (BCmp (Variable "y", Integer 1), BNot (BCmp (Variable "x", Integer 1))), BNot (BCmp (Variable "x", Minus (Variable "n", Integer 1))))),
|
(BAnd
|
||||||
|
(BAnd (BCmp (Variable "y", Integer 1),
|
||||||
|
BNot (BCmp (Variable "x",
|
||||||
|
Integer 1))),
|
||||||
|
BNot (BCmp (Variable "x",
|
||||||
|
Minus (Variable "n",
|
||||||
|
Integer 1))))),
|
||||||
(Assignment ("result", Integer 1)),
|
(Assignment ("result", Integer 1)),
|
||||||
(Skip)
|
(Skip)
|
||||||
))),
|
))),
|
||||||
|
|||||||
@ -13,8 +13,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Error (`AbsentAssignment _) -> Printf.printf "Error absent assignment program: error (success)\n"
|
| Error (`AbsentAssignment _) ->
|
||||||
| _ -> Printf.printf "Error absent assignment program: failed\n"
|
Printf.printf "Error absent assignment program: error (success)\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Error absent assignment program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Error wrong return type program *)
|
(* Error wrong return type program *)
|
||||||
@ -28,8 +30,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Error (`WrongTypeSpecification _) -> Printf.printf "Error wrong return type program: error (success)\n"
|
| Error (`WrongTypeSpecification _) ->
|
||||||
| _ -> Printf.printf "Error wrong return type program: failed\n"
|
Printf.printf "Error wrong return type program: error (success)\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Error wrong return type program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Error wrong specification program *)
|
(* Error wrong specification program *)
|
||||||
@ -43,8 +47,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Error (`WrongTypeSpecification _) -> Printf.printf "Error wrong specification program: error (success)\n"
|
| Error (`WrongTypeSpecification _) ->
|
||||||
| _ -> Printf.printf "Error wrong specification program: failed\n"
|
Printf.printf "Error wrong specification program: error (success)\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Error wrong specification program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Error wrong input type program *)
|
(* Error wrong input type program *)
|
||||||
@ -61,8 +67,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Error (`WrongType _) -> Printf.printf "Error wrong input type program: error (success)\n"
|
| Error (`WrongType _) ->
|
||||||
| _ -> Printf.printf "Error wrong input type program: failed\n"
|
Printf.printf "Error wrong input type program: error (success)\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Error wrong input type program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Error not a function program *)
|
(* Error not a function program *)
|
||||||
@ -75,8 +83,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Error (`WrongType _) -> Printf.printf "Error not a function program: error (success)\n"
|
| Error (`WrongType _) ->
|
||||||
| _ -> Printf.printf "Error not a function program: failed\n"
|
Printf.printf "Error not a function program: error (success)\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Error not a function program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Error if branches with different types program *)
|
(* Error if branches with different types program *)
|
||||||
@ -90,8 +100,11 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Error (`WrongType _) -> Printf.printf "Error if branches with different types program: error (success)\n"
|
| Error (`WrongType _) ->
|
||||||
| _ -> Printf.printf "Error if branches with different types program: failed\n"
|
Printf.printf
|
||||||
|
"Error if branches with different types program: error (success)\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Error if branches with different types program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Error if guard is not a boolean program *)
|
(* Error if guard is not a boolean program *)
|
||||||
@ -105,8 +118,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Error (`WrongType _) -> Printf.printf "Error if guard is not a boolean program: error (success)\n"
|
| Error (`WrongType _) ->
|
||||||
| _ -> Printf.printf "Error if guard is not a boolean program: failed\n"
|
Printf.printf "Error if guard is not a boolean program: error (success)\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Error if guard is not a boolean program: failed\n"
|
||||||
|
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
@ -120,8 +135,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Identity program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Identity program: failed\n"
|
Printf.printf "Identity program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Identity program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Constant program *)
|
(* Constant program *)
|
||||||
@ -134,8 +151,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Constant program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Constant program: failed\n"
|
Printf.printf "Constant program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Constant program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Partial application of function program *)
|
(* Partial application of function program *)
|
||||||
@ -155,8 +174,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Partial application of function program 1: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Partial application of function program 1: failed\n"
|
Printf.printf "Partial application of function program 1: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Partial application of function program 1: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Partial application of function program *)
|
(* Partial application of function program *)
|
||||||
@ -173,8 +194,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Partial application of function program 2: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Partial application of function program 2: failed\n"
|
Printf.printf "Partial application of function program 2: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Partial application of function program 2: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Passing functions to functions program *)
|
(* Passing functions to functions program *)
|
||||||
@ -183,10 +206,13 @@ let program =
|
|||||||
("f",
|
("f",
|
||||||
(Function (
|
(Function (
|
||||||
"z",
|
"z",
|
||||||
FunctionType (FunctionType (IntegerType, IntegerType), FunctionType (FunctionType (IntegerType, IntegerType), FunctionType (IntegerType, IntegerType))),
|
FunctionType (FunctionType (IntegerType, IntegerType),
|
||||||
|
FunctionType (FunctionType (IntegerType, IntegerType),
|
||||||
|
FunctionType (IntegerType, IntegerType))),
|
||||||
(Function (
|
(Function (
|
||||||
"y",
|
"y",
|
||||||
FunctionType (FunctionType (IntegerType, IntegerType), FunctionType (IntegerType, IntegerType)),
|
FunctionType (FunctionType (IntegerType, IntegerType),
|
||||||
|
FunctionType (IntegerType, IntegerType)),
|
||||||
Function (
|
Function (
|
||||||
"x",
|
"x",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
@ -201,18 +227,23 @@ let program =
|
|||||||
(
|
(
|
||||||
(Application
|
(Application
|
||||||
(Variable "f",
|
(Variable "f",
|
||||||
Function ("x", FunctionType (IntegerType, IntegerType), Plus (Variable "x", Integer 1))
|
Function ("x", FunctionType (IntegerType, IntegerType),
|
||||||
|
Plus (Variable "x", Integer 1))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Function ("x", FunctionType (IntegerType, IntegerType), Minus (Variable "x", Integer 1))
|
Function ("x", FunctionType (IntegerType, IntegerType),
|
||||||
|
Minus (Variable "x", Integer 1))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Passing functions to functions program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Passing functions to functions program: failed\n"
|
Printf.printf "Passing functions to functions program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Passing functions to functions program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Recursive function program *)
|
(* Recursive function program *)
|
||||||
@ -221,28 +252,40 @@ let program =
|
|||||||
("f",
|
("f",
|
||||||
"x",
|
"x",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
(IfThenElse (CmpLess (Variable "x", Integer 2),Integer 1, Plus (Variable "x", Application (Variable "f", Minus (Variable "x", Integer 1))))),
|
(IfThenElse (CmpLess (Variable "x", Integer 2),
|
||||||
|
Integer 1,
|
||||||
|
Plus (
|
||||||
|
Variable "x",
|
||||||
|
Application (
|
||||||
|
Variable "f",
|
||||||
|
Minus (Variable "x", Integer 1))))),
|
||||||
(Variable "f")
|
(Variable "f")
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Recursive function program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Recursive function program: failed\n"
|
Printf.printf "Recursive function program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Recursive function program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Scope program *)
|
(* Scope program *)
|
||||||
let program =
|
let program =
|
||||||
LetIn
|
LetIn
|
||||||
("f",
|
("f",
|
||||||
(LetIn ("a", Integer 1, (Function ("y", FunctionType (IntegerType, IntegerType), Plus (Variable "y", Variable "a"))))),
|
(LetIn ("a", Integer 1, (Function ("y",
|
||||||
|
FunctionType (IntegerType, IntegerType),
|
||||||
|
Plus (Variable "y", Variable "a"))))),
|
||||||
(LetIn ("a", Integer 2, Variable "f"))
|
(LetIn ("a", Integer 2, Variable "f"))
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Scope program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Scope program: failed\n"
|
Printf.printf "Scope program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Scope program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Factorial program *)
|
(* Factorial program *)
|
||||||
@ -251,14 +294,20 @@ let program =
|
|||||||
"f",
|
"f",
|
||||||
"x",
|
"x",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
(IfThenElse (CmpLessEq (Variable "x", Integer 0), Integer 1, Times (Variable "x", Application (Variable "f", Minus (Variable "x", Integer 1))))),
|
(IfThenElse (CmpLessEq (Variable "x", Integer 0),
|
||||||
|
Integer 1,
|
||||||
|
Times (Variable "x",
|
||||||
|
Application (Variable "f",
|
||||||
|
Minus (Variable "x", Integer 1))))),
|
||||||
(Variable "f")
|
(Variable "f")
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Factorial program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Factorial program: failed\n"
|
Printf.printf "Factorial program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Factorial program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Hailstone sequence's lenght program *)
|
(* Hailstone sequence's lenght program *)
|
||||||
@ -270,27 +319,41 @@ let program =
|
|||||||
FunctionType (TupleType (IntegerType, IntegerType), IntegerType),
|
FunctionType (TupleType (IntegerType, IntegerType), IntegerType),
|
||||||
(
|
(
|
||||||
IfThenElse (BNot (Cmp (First (Variable "input"), Integer 1)),
|
IfThenElse (BNot (Cmp (First (Variable "input"), Integer 1)),
|
||||||
(IfThenElse (Cmp (Modulo (First (Variable "input"), Integer 2), Integer 0),
|
(IfThenElse (Cmp (Modulo (First (Variable "input"),
|
||||||
|
Integer 2),
|
||||||
|
Integer 0),
|
||||||
Application (Variable "collatz",
|
Application (Variable "collatz",
|
||||||
Tuple (
|
Tuple (
|
||||||
Division (First (Variable "input"), Integer 2),
|
Division (First
|
||||||
Plus (Integer 1, Second (Variable "input")))),
|
(Variable "input"),
|
||||||
|
Integer 2),
|
||||||
|
Plus (Integer 1, Second
|
||||||
|
(Variable "input")))),
|
||||||
Application (Variable "collatz",
|
Application (Variable "collatz",
|
||||||
Tuple (
|
Tuple (
|
||||||
Plus (Integer 1, Times (Integer 3, First (Variable "input"))),
|
Plus
|
||||||
Plus (Integer 1, Second (Variable "input")))))),
|
(Integer 1,
|
||||||
|
Times
|
||||||
|
(Integer 3,
|
||||||
|
First (Variable "input"))),
|
||||||
|
Plus (
|
||||||
|
Integer 1,
|
||||||
|
Second (Variable "input")))))),
|
||||||
(Second (Variable "input")))
|
(Second (Variable "input")))
|
||||||
),
|
),
|
||||||
(Function ("x",
|
(Function ("x",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
Application (Variable "collatz", Tuple (Variable "x", Integer 1)))
|
Application (Variable "collatz",
|
||||||
)
|
Tuple (Variable "x", Integer 1))))
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Hailstone sequence's lenght program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Hailstone sequence's lenght program: failed\n"
|
Printf.printf "Hailstone sequence's lenght program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Hailstone sequence's lenght program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Sum multiples of 3 and 5 program *)
|
(* Sum multiples of 3 and 5 program *)
|
||||||
@ -300,11 +363,15 @@ let program =
|
|||||||
"sum",
|
"sum",
|
||||||
"n",
|
"n",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
(IfThenElse ((BOr (Cmp (Modulo (Variable "n", Integer 3), Integer 0), Cmp (Modulo (Variable "n", Integer 5), Integer 0))),
|
(IfThenElse ((BOr (Cmp (Modulo (Variable "n", Integer 3), Integer 0),
|
||||||
Plus (Variable "n", Application (Variable "sum", Minus (Variable "n", Integer 1))),
|
Cmp (Modulo (Variable "n", Integer 5), Integer 0))),
|
||||||
|
Plus (Variable "n",
|
||||||
|
Application (Variable "sum",
|
||||||
|
Minus (Variable "n", Integer 1))),
|
||||||
(IfThenElse ((CmpLessEq (Variable "n", Integer 1)),
|
(IfThenElse ((CmpLessEq (Variable "n", Integer 1)),
|
||||||
(Integer 0),
|
(Integer 0),
|
||||||
(Application (Variable "sum", Minus (Variable "n", Integer 1))))
|
(Application (Variable "sum",
|
||||||
|
Minus (Variable "n", Integer 1))))
|
||||||
))
|
))
|
||||||
),
|
),
|
||||||
(Variable "sum")
|
(Variable "sum")
|
||||||
@ -312,8 +379,10 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Sum multiples of 3 and 5 program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Sum multiples of 3 and 5 program: failed\n"
|
Printf.printf "Sum multiples of 3 and 5 program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Sum multiples of 3 and 5 program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Rand program *)
|
(* Rand program *)
|
||||||
@ -327,30 +396,56 @@ let program =
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Rand program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Rand program: failed\n"
|
Printf.printf "Rand program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Rand program: failed\n"
|
||||||
|
|
||||||
(* -------------------------------------------------------------------------- *)
|
(* -------------------------------------------------------------------------- *)
|
||||||
(* Fibonacci program *)
|
(* Fibonacci program *)
|
||||||
let program =
|
let program =
|
||||||
LetFun (
|
LetFun (
|
||||||
"fib",
|
"fib",
|
||||||
"input",
|
"i",
|
||||||
FunctionType (TupleType (TupleType (IntegerType, IntegerType), IntegerType), IntegerType),
|
FunctionType (IntegerType, FunctionType
|
||||||
(IfThenElse (Cmp (First (First (Variable "input")), Integer 0),
|
(IntegerType, FunctionType (IntegerType, IntegerType))),
|
||||||
Second (First (Variable "input")),
|
Function (
|
||||||
Application (Variable "fib",
|
"a",
|
||||||
Tuple ( Tuple (
|
FunctionType (IntegerType, FunctionType (IntegerType, IntegerType)),
|
||||||
Minus (First (First (Variable "input")), Integer 1),
|
Function (
|
||||||
Second (Variable "input")),
|
"b",
|
||||||
Plus (Second (First (Variable "input")), Second (Variable "input"))))
|
FunctionType (IntegerType, IntegerType),
|
||||||
)),
|
(IfThenElse (Cmp (Variable "i", Integer 0),
|
||||||
|
Variable "a",
|
||||||
|
Application (
|
||||||
|
Application (
|
||||||
|
Application (
|
||||||
|
Variable "fib",
|
||||||
|
Minus (Variable "i", Integer 1)),
|
||||||
|
Variable "b"),
|
||||||
|
Plus (Variable "a", Variable "b")
|
||||||
|
)
|
||||||
|
))
|
||||||
|
)
|
||||||
|
),
|
||||||
Function ("x",
|
Function ("x",
|
||||||
FunctionType (IntegerType, IntegerType),
|
FunctionType (IntegerType, IntegerType),
|
||||||
(Application (Variable "fib", Tuple (Tuple (Variable "x", Integer 0), Integer 1))))
|
Application (
|
||||||
|
Application (
|
||||||
|
Application (
|
||||||
|
Variable "fib",
|
||||||
|
Variable "x"
|
||||||
|
),
|
||||||
|
Integer 0
|
||||||
|
),
|
||||||
|
Integer 1
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
match typecheck program with
|
match typecheck program with
|
||||||
Ok _ -> Printf.printf "Fibonacci program: success\n"
|
| Ok _ ->
|
||||||
| _ -> Printf.printf "Fibonacci program: failed\n"
|
Printf.printf "Fibonacci program: success\n"
|
||||||
|
| _ ->
|
||||||
|
Printf.printf "Fibonacci program: failed\n"
|
||||||
|
|||||||
@ -215,7 +215,10 @@ match get_result program with
|
|||||||
(* Sum multiples of 3 and 5 program *)
|
(* Sum multiples of 3 and 5 program *)
|
||||||
|
|
||||||
let program =
|
let program =
|
||||||
"let rec sum n: int -> int = if n % 3 == 0 || n % 5 == 0 then n + sum (n - 1) else if n < 1 then 0 else sum (n - 1) in sum"
|
"let rec sum n: int -> int =
|
||||||
|
if n % 3 == 0 || n % 5 == 0
|
||||||
|
then n + sum (n - 1)
|
||||||
|
else if n < 1 then 0 else sum (n - 1) in sum"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
Printf.printf "Sum multiples of 3 and 5 program: ";
|
Printf.printf "Sum multiples of 3 and 5 program: ";
|
||||||
|
|||||||
Reference in New Issue
Block a user