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