2024-11-13 21:50:44 +01:00
|
|
|
open MiniFun.TypeChecker
|
|
|
|
|
open MiniFun.Types
|
2024-10-24 15:35:42 +02:00
|
|
|
|
2024-10-24 16:27:57 +02:00
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Error absent assignment program *)
|
|
|
|
|
|
|
|
|
|
let program =
|
|
|
|
|
Function
|
2024-11-15 17:23:04 +01:00
|
|
|
("a",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2024-10-26 02:11:00 +02:00
|
|
|
Variable "x"
|
2024-10-24 16:27:57 +02:00
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Error (`AbsentAssignment _) ->
|
|
|
|
|
Printf.printf "Error absent assignment program: error (success)\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Error absent assignment program: failed\n"
|
2024-10-24 16:27:57 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Error wrong return type program *)
|
|
|
|
|
|
|
|
|
|
let program =
|
|
|
|
|
Function
|
2024-11-15 17:23:04 +01:00
|
|
|
("a",
|
|
|
|
|
FunctionType (IntegerType, BooleanType),
|
2024-10-24 16:27:57 +02:00
|
|
|
(Variable "a")
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Error (`WrongTypeSpecification _) ->
|
|
|
|
|
Printf.printf "Error wrong return type program: error (success)\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Error wrong return type program: failed\n"
|
2024-10-24 16:27:57 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Error wrong specification program *)
|
|
|
|
|
|
|
|
|
|
let program =
|
|
|
|
|
Function
|
2024-11-15 17:23:04 +01:00
|
|
|
("a",
|
2024-10-24 16:27:57 +02:00
|
|
|
IntegerType,
|
|
|
|
|
(Variable "a")
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Error (`WrongTypeSpecification _) ->
|
|
|
|
|
Printf.printf "Error wrong specification program: error (success)\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Error wrong specification program: failed\n"
|
2024-10-24 16:27:57 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Error wrong input type program *)
|
|
|
|
|
|
|
|
|
|
let program =
|
|
|
|
|
Application (
|
|
|
|
|
Function
|
2024-11-15 17:23:04 +01:00
|
|
|
("a",
|
|
|
|
|
FunctionType (IntegerType, FunctionType (IntegerType, IntegerType)),
|
|
|
|
|
Function ("b", FunctionType (IntegerType, IntegerType), Variable "a")
|
2024-10-24 16:27:57 +02:00
|
|
|
),
|
2024-11-15 17:23:04 +01:00
|
|
|
Boolean false
|
2024-10-24 16:27:57 +02:00
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Error (`WrongType _) ->
|
|
|
|
|
Printf.printf "Error wrong input type program: error (success)\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Error wrong input type program: failed\n"
|
2024-10-24 16:27:57 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Error not a function program *)
|
|
|
|
|
|
|
|
|
|
let program =
|
|
|
|
|
Application (
|
|
|
|
|
Integer 0,
|
2024-11-15 17:23:04 +01:00
|
|
|
Boolean false
|
2024-10-24 16:27:57 +02:00
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Error (`WrongType _) ->
|
|
|
|
|
Printf.printf "Error not a function program: error (success)\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Error not a function program: failed\n"
|
2024-10-24 16:27:57 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Error if branches with different types program *)
|
|
|
|
|
|
|
|
|
|
let program =
|
|
|
|
|
Function (
|
2024-11-15 17:23:04 +01:00
|
|
|
"x",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2024-10-24 16:27:57 +02:00
|
|
|
IfThenElse (Cmp (Integer 1, Integer 2), Boolean true, Integer 1)
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| 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"
|
2024-10-24 16:27:57 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Error if guard is not a boolean program *)
|
|
|
|
|
|
|
|
|
|
let program =
|
|
|
|
|
Function (
|
2024-11-15 17:23:04 +01:00
|
|
|
"x",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2024-10-24 16:27:57 +02:00
|
|
|
IfThenElse (Integer 1, Integer 2, Integer 1)
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| 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"
|
2024-10-24 16:27:57 +02:00
|
|
|
|
|
|
|
|
|
2024-10-24 15:35:42 +02:00
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Identity program *)
|
|
|
|
|
let program =
|
|
|
|
|
Function
|
2024-11-15 17:23:04 +01:00
|
|
|
("a",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2024-10-24 15:35:42 +02:00
|
|
|
(Variable "a")
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Identity program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Identity program: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Constant program *)
|
|
|
|
|
let program =
|
|
|
|
|
Function
|
2024-11-15 17:23:04 +01:00
|
|
|
("a",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2024-10-24 15:35:42 +02:00
|
|
|
(Integer 1)
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Constant program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Constant program: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Partial application of function program *)
|
|
|
|
|
let program =
|
|
|
|
|
LetIn
|
|
|
|
|
("f",
|
2024-11-15 17:23:04 +01:00
|
|
|
(Function (
|
|
|
|
|
"x",
|
|
|
|
|
FunctionType (IntegerType, FunctionType (IntegerType, IntegerType)),
|
|
|
|
|
Function ("y",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
|
|
|
|
Plus (Variable "x", Variable "y")
|
|
|
|
|
)
|
|
|
|
|
)),
|
|
|
|
|
(Application (Variable "f", Integer 3))
|
2024-10-24 15:35:42 +02:00
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Partial application of function program 1: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Partial application of function program 1: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Partial application of function program *)
|
|
|
|
|
let program =
|
|
|
|
|
LetFun
|
|
|
|
|
("f",
|
2024-11-15 17:23:04 +01:00
|
|
|
"x",
|
|
|
|
|
FunctionType (IntegerType, FunctionType (IntegerType, IntegerType)),
|
|
|
|
|
(Function ("y",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2024-10-24 15:35:42 +02:00
|
|
|
Plus (Variable "x", Variable "y"))),
|
2024-11-15 17:23:04 +01:00
|
|
|
(Application (Variable "f", Integer 3))
|
2024-10-24 15:35:42 +02:00
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Partial application of function program 2: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Partial application of function program 2: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Passing functions to functions program *)
|
|
|
|
|
let program =
|
|
|
|
|
LetIn
|
|
|
|
|
("f",
|
|
|
|
|
(Function (
|
2024-11-15 17:23:04 +01:00
|
|
|
"z",
|
2025-01-26 22:07:53 +01:00
|
|
|
FunctionType (FunctionType (IntegerType, IntegerType),
|
|
|
|
|
FunctionType (FunctionType (IntegerType, IntegerType),
|
|
|
|
|
FunctionType (IntegerType, IntegerType))),
|
2024-10-24 15:35:42 +02:00
|
|
|
(Function (
|
2024-11-15 17:23:04 +01:00
|
|
|
"y",
|
2025-01-26 22:07:53 +01:00
|
|
|
FunctionType (FunctionType (IntegerType, IntegerType),
|
|
|
|
|
FunctionType (IntegerType, IntegerType)),
|
2024-10-24 15:35:42 +02:00
|
|
|
Function (
|
2024-11-15 17:23:04 +01:00
|
|
|
"x",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2024-10-24 15:35:42 +02:00
|
|
|
(IfThenElse (
|
|
|
|
|
CmpLess (Variable "x", Integer 0),
|
2024-11-15 17:23:04 +01:00
|
|
|
(Application (Variable "y", Variable "x")),
|
|
|
|
|
(Application (Variable "z", Variable "x"))
|
2024-10-24 15:35:42 +02:00
|
|
|
)))
|
|
|
|
|
))
|
|
|
|
|
)),
|
|
|
|
|
(Application
|
|
|
|
|
(
|
|
|
|
|
(Application
|
|
|
|
|
(Variable "f",
|
2025-01-26 22:07:53 +01:00
|
|
|
Function ("x", FunctionType (IntegerType, IntegerType),
|
|
|
|
|
Plus (Variable "x", Integer 1))
|
2024-10-24 15:35:42 +02:00
|
|
|
)
|
|
|
|
|
),
|
2025-01-26 22:07:53 +01:00
|
|
|
Function ("x", FunctionType (IntegerType, IntegerType),
|
|
|
|
|
Minus (Variable "x", Integer 1))
|
2024-10-24 15:35:42 +02:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2025-01-26 22:07:53 +01:00
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Passing functions to functions program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Passing functions to functions program: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Recursive function program *)
|
|
|
|
|
let program =
|
|
|
|
|
LetFun
|
|
|
|
|
("f",
|
2024-11-15 17:23:04 +01:00
|
|
|
"x",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2025-01-26 22:07:53 +01:00
|
|
|
(IfThenElse (CmpLess (Variable "x", Integer 2),
|
|
|
|
|
Integer 1,
|
|
|
|
|
Plus (
|
|
|
|
|
Variable "x",
|
|
|
|
|
Application (
|
|
|
|
|
Variable "f",
|
|
|
|
|
Minus (Variable "x", Integer 1))))),
|
2024-10-24 15:35:42 +02:00
|
|
|
(Variable "f")
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Recursive function program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Recursive function program: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Scope program *)
|
|
|
|
|
let program =
|
|
|
|
|
LetIn
|
|
|
|
|
("f",
|
2025-01-26 22:07:53 +01:00
|
|
|
(LetIn ("a", Integer 1, (Function ("y",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
|
|
|
|
Plus (Variable "y", Variable "a"))))),
|
2024-10-24 15:35:42 +02:00
|
|
|
(LetIn ("a", Integer 2, Variable "f"))
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Scope program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Scope program: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Factorial program *)
|
|
|
|
|
let program =
|
|
|
|
|
LetFun (
|
|
|
|
|
"f",
|
2024-11-15 17:23:04 +01:00
|
|
|
"x",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2025-01-26 22:07:53 +01:00
|
|
|
(IfThenElse (CmpLessEq (Variable "x", Integer 0),
|
|
|
|
|
Integer 1,
|
|
|
|
|
Times (Variable "x",
|
|
|
|
|
Application (Variable "f",
|
|
|
|
|
Minus (Variable "x", Integer 1))))),
|
2024-10-24 15:35:42 +02:00
|
|
|
(Variable "f")
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Factorial program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Factorial program: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Hailstone sequence's lenght program *)
|
|
|
|
|
|
|
|
|
|
let program =
|
|
|
|
|
LetFun (
|
|
|
|
|
"collatz",
|
2024-11-15 17:23:04 +01:00
|
|
|
"input",
|
|
|
|
|
FunctionType (TupleType (IntegerType, IntegerType), IntegerType),
|
2024-10-24 15:35:42 +02:00
|
|
|
(
|
2024-11-15 17:23:04 +01:00
|
|
|
IfThenElse (BNot (Cmp (First (Variable "input"), Integer 1)),
|
2025-01-26 22:07:53 +01:00
|
|
|
(IfThenElse (Cmp (Modulo (First (Variable "input"),
|
|
|
|
|
Integer 2),
|
|
|
|
|
Integer 0),
|
2024-11-15 17:23:04 +01:00
|
|
|
Application (Variable "collatz",
|
|
|
|
|
Tuple (
|
2025-01-26 22:07:53 +01:00
|
|
|
Division (First
|
|
|
|
|
(Variable "input"),
|
|
|
|
|
Integer 2),
|
|
|
|
|
Plus (Integer 1, Second
|
|
|
|
|
(Variable "input")))),
|
2024-11-15 17:23:04 +01:00
|
|
|
Application (Variable "collatz",
|
|
|
|
|
Tuple (
|
2025-01-26 22:07:53 +01:00
|
|
|
Plus
|
|
|
|
|
(Integer 1,
|
|
|
|
|
Times
|
|
|
|
|
(Integer 3,
|
|
|
|
|
First (Variable "input"))),
|
|
|
|
|
Plus (
|
|
|
|
|
Integer 1,
|
|
|
|
|
Second (Variable "input")))))),
|
2024-11-15 17:23:04 +01:00
|
|
|
(Second (Variable "input")))
|
2024-10-24 15:35:42 +02:00
|
|
|
),
|
2024-11-15 17:23:04 +01:00
|
|
|
(Function ("x",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2025-01-26 22:07:53 +01:00
|
|
|
Application (Variable "collatz",
|
|
|
|
|
Tuple (Variable "x", Integer 1))))
|
2024-10-24 15:35:42 +02:00
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2025-01-26 22:07:53 +01:00
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Hailstone sequence's lenght program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Hailstone sequence's lenght program: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Sum multiples of 3 and 5 program *)
|
|
|
|
|
|
|
|
|
|
let program =
|
|
|
|
|
LetFun (
|
|
|
|
|
"sum",
|
2024-11-15 17:23:04 +01:00
|
|
|
"n",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2025-01-26 22:07:53 +01:00
|
|
|
(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))),
|
2024-10-24 15:35:42 +02:00
|
|
|
(IfThenElse ((CmpLessEq (Variable "n", Integer 1)),
|
|
|
|
|
(Integer 0),
|
2025-01-26 22:07:53 +01:00
|
|
|
(Application (Variable "sum",
|
|
|
|
|
Minus (Variable "n", Integer 1))))
|
2024-10-24 15:35:42 +02:00
|
|
|
))
|
|
|
|
|
),
|
|
|
|
|
(Variable "sum")
|
|
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Sum multiples of 3 and 5 program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Sum multiples of 3 and 5 program: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Rand program *)
|
|
|
|
|
let program =
|
|
|
|
|
Function (
|
2024-11-15 17:23:04 +01:00
|
|
|
"x",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2024-10-24 15:35:42 +02:00
|
|
|
Rand (Variable "x")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Rand program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Rand program: failed\n"
|
2024-10-24 15:35:42 +02:00
|
|
|
|
|
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
|
|
(* Fibonacci program *)
|
|
|
|
|
let program =
|
|
|
|
|
LetFun (
|
|
|
|
|
"fib",
|
2025-01-26 22:07:53 +01:00
|
|
|
"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")
|
|
|
|
|
)
|
|
|
|
|
))
|
|
|
|
|
)
|
|
|
|
|
),
|
2024-11-15 17:23:04 +01:00
|
|
|
Function ("x",
|
|
|
|
|
FunctionType (IntegerType, IntegerType),
|
2025-01-26 22:07:53 +01:00
|
|
|
Application (
|
|
|
|
|
Application (
|
|
|
|
|
Application (
|
|
|
|
|
Variable "fib",
|
|
|
|
|
Variable "x"
|
|
|
|
|
),
|
|
|
|
|
Integer 0
|
|
|
|
|
),
|
|
|
|
|
Integer 1
|
|
|
|
|
)
|
|
|
|
|
)
|
2024-10-24 15:35:42 +02:00
|
|
|
)
|
|
|
|
|
;;
|
|
|
|
|
|
2024-10-26 01:47:30 +02:00
|
|
|
match typecheck program with
|
2025-01-26 22:07:53 +01:00
|
|
|
| Ok _ ->
|
|
|
|
|
Printf.printf "Fibonacci program: success\n"
|
|
|
|
|
| _ ->
|
|
|
|
|
Printf.printf "Fibonacci program: failed\n"
|