Refactoring, errors are not thrown anymore
This commit is contained in:
@ -11,7 +11,7 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Identity program: %d\n" (reduce program 1)
|
||||
Printf.printf "Identity program: %d\n" (Result.get_ok (reduce program 1))
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Constant program *)
|
||||
@ -23,7 +23,7 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Constant program: %d\n" (reduce program 10)
|
||||
Printf.printf "Constant program: %d\n" (Result.get_ok (reduce program 10))
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Partial application of function program *)
|
||||
@ -37,7 +37,7 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Partial application of function program: %d\n" (reduce program 2)
|
||||
Printf.printf "Partial application of function program: %d\n" (Result.get_ok (reduce program 2))
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Partial application of function program *)
|
||||
@ -53,7 +53,7 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Partial application of function program: %d\n" (reduce program 3)
|
||||
Printf.printf "Partial application of function program: %d\n" (Result.get_ok (reduce program 3))
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Passing functions to functions program *)
|
||||
@ -89,8 +89,8 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Passing functions to functions program 1: %d\n" (reduce program (3));
|
||||
Printf.printf "Passing functions to functions program 2: %d\n" (reduce program (-3))
|
||||
Printf.printf "Passing functions to functions program 1: %d\n" (Result.get_ok (reduce program (3)));
|
||||
Printf.printf "Passing functions to functions program 2: %d\n" (Result.get_ok (reduce program (-3)))
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Recursive function program *)
|
||||
@ -104,7 +104,7 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Recursive function program: %d\n" (reduce program 10)
|
||||
Printf.printf "Recursive function program: %d\n" (Result.get_ok (reduce program 10))
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Scope program *)
|
||||
@ -116,7 +116,7 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Scope program: %d\n" (reduce program 4)
|
||||
Printf.printf "Scope program: %d\n" (Result.get_ok (reduce program 4))
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Factorial program *)
|
||||
@ -130,7 +130,7 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Factorial program: %d\n" (reduce program 10)
|
||||
Printf.printf "Factorial program: %d\n" (Result.get_ok (reduce program 10))
|
||||
;;
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
@ -154,7 +154,7 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Hailstone sequence's lenght program: %d\n" (reduce program 77031)
|
||||
Printf.printf "Hailstone sequence's lenght program: %d\n" (Result.get_ok (reduce program 77031))
|
||||
;;
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
@ -176,7 +176,7 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Sum multiples of 3 and 5 program: %d\n" (reduce program 12345)
|
||||
Printf.printf "Sum multiples of 3 and 5 program: %d\n" (Result.get_ok (reduce program 12345))
|
||||
;;
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
@ -190,7 +190,7 @@ let program =
|
||||
|
||||
;;
|
||||
|
||||
Printf.printf "Rand program: %b\n" ((reduce program 10) < 10)
|
||||
Printf.printf "Rand program: %b\n" ((Result.get_ok (reduce program 10) < 10))
|
||||
;;
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
@ -213,5 +213,5 @@ let program =
|
||||
|
||||
;;
|
||||
|
||||
Printf.printf "Fibonacci program: %d\n" (reduce program 48)
|
||||
Printf.printf "Fibonacci program: %d\n" (Result.get_ok (reduce program 48))
|
||||
;;
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
Error absent assignment program: error
|
||||
Error wrong arity program 1: error
|
||||
Error wrong arity program 2: error
|
||||
Error wrong return type program: error
|
||||
Error wrong specification program: error
|
||||
Error wrong input type program: error
|
||||
Error not a function program: error
|
||||
Error if branches with different types program: error
|
||||
Error if guard is not a boolean program: error
|
||||
Identity program: true
|
||||
Constant program: true
|
||||
Partial application of function program: true
|
||||
Partial application of function program: true
|
||||
Passing functions to functions program: true
|
||||
Recursive function program: true
|
||||
Scope program: true
|
||||
Factorial program: true
|
||||
Hailstone sequence's lenght program: true
|
||||
Sum multiples of 3 and 5 program: true
|
||||
Rand program: true
|
||||
Fibonacci program: true
|
||||
Error absent assignment program: error (success)
|
||||
Error wrong arity program 1: error (success)
|
||||
Error wrong arity program 2: error (success)
|
||||
Error wrong return type program: error (success)
|
||||
Error wrong specification program: error (success)
|
||||
Error wrong input type program: error (success)
|
||||
Error not a function program: error (success)
|
||||
Error if branches with different types program: error (success)
|
||||
Error if guard is not a boolean program: error (success)
|
||||
Identity program: success
|
||||
Constant program: success
|
||||
Partial application of function program 1: success
|
||||
Partial application of function program 2: success
|
||||
Passing functions to functions program: success
|
||||
Recursive function program: success
|
||||
Scope program: success
|
||||
Factorial program: success
|
||||
Hailstone sequence's lenght program: success
|
||||
Sum multiples of 3 and 5 program: success
|
||||
Rand program: success
|
||||
Fibonacci program: success
|
||||
|
||||
@ -8,14 +8,13 @@ let program =
|
||||
Function
|
||||
(["a"],
|
||||
FunctionType ([IntegerType], IntegerType),
|
||||
(Variable "x")
|
||||
Plus (Variable "x", Integer 1)
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error absent assignment program: %b\n" (typecheck program)
|
||||
with AbsentAssignment _ ->
|
||||
Printf.printf "Error absent assignment program: error\n"
|
||||
match typecheck program with
|
||||
Error (`AbsentAssignment _) -> Printf.printf "Error absent assignment program: error (success)\n"
|
||||
| _ -> Printf.printf "Error absent assignment program: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error wrong arity program *)
|
||||
@ -28,10 +27,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong arity program 1: %b\n" (typecheck program)
|
||||
with WrongTypeSpecification _ ->
|
||||
Printf.printf "Error wrong arity program 1: error\n"
|
||||
match typecheck program with
|
||||
Error (`WrongTypeSpecification _) -> Printf.printf "Error wrong arity program 1: error (success)\n"
|
||||
| _ -> Printf.printf "Error wrong arity program 1: failed\n"
|
||||
|
||||
let program =
|
||||
LetFun
|
||||
@ -43,11 +41,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong arity program 2: %b\n" (typecheck program)
|
||||
with WrongArity _ ->
|
||||
Printf.printf "Error wrong arity program 2: error\n"
|
||||
|
||||
match typecheck program with
|
||||
Error (`WrongArity _) -> Printf.printf "Error wrong arity program 2: error (success)\n"
|
||||
| _ -> Printf.printf "Error wrong arity program 2: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error wrong return type program *)
|
||||
@ -60,10 +56,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong return type program: %b\n" (typecheck program)
|
||||
with WrongTypeSpecification _ ->
|
||||
Printf.printf "Error wrong return type program: error\n"
|
||||
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 wrong specification program *)
|
||||
@ -76,10 +71,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong specification program: %b\n" (typecheck program)
|
||||
with WrongTypeSpecification _ ->
|
||||
Printf.printf "Error wrong specification program: error\n"
|
||||
match typecheck program with
|
||||
Error (`WrongTypeSpecification _) -> Printf.printf "Error wrong specification program: error (success)\n"
|
||||
| _ -> Printf.printf "Error wrong specification program: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error wrong input type program *)
|
||||
@ -95,10 +89,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong input type program: %b\n" (typecheck program)
|
||||
with WrongType _ ->
|
||||
Printf.printf "Error wrong input type program: error\n"
|
||||
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 not a function program *)
|
||||
@ -110,10 +103,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error not a function program: %b\n" (typecheck program)
|
||||
with WrongType _ ->
|
||||
Printf.printf "Error not a function program: error\n"
|
||||
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 if branches with different types program *)
|
||||
@ -126,10 +118,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error if branches with different types program: %b\n" (typecheck program)
|
||||
with WrongType _ ->
|
||||
Printf.printf "Error if branches with different types program: error\n"
|
||||
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 if guard is not a boolean program *)
|
||||
@ -142,11 +133,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error if guard is not a boolean program: %b\n" (typecheck program)
|
||||
with WrongType _ ->
|
||||
Printf.printf "Error if guard is not a boolean program: error\n"
|
||||
|
||||
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"
|
||||
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
@ -159,7 +148,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Identity program: %b\n" (typecheck program)
|
||||
match typecheck program with
|
||||
Ok _ -> Printf.printf "Identity program: success\n"
|
||||
| _ -> Printf.printf "Identity program: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Constant program *)
|
||||
@ -171,7 +162,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Constant program: %b\n" (typecheck program)
|
||||
match typecheck program with
|
||||
Ok _ -> Printf.printf "Constant program: success\n"
|
||||
| _ -> Printf.printf "Constant program: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Partial application of function program *)
|
||||
@ -185,7 +178,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Partial application of function program: %b\n" (typecheck 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"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Partial application of function program *)
|
||||
@ -201,7 +196,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Partial application of function program: %b\n" (typecheck 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"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Passing functions to functions program *)
|
||||
@ -237,7 +234,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Passing functions to functions program: %b\n" (typecheck program)
|
||||
match typecheck program with
|
||||
Ok _ -> Printf.printf "Passing functions to functions program: success\n"
|
||||
| _ -> Printf.printf "Passing functions to functions program: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Recursive function program *)
|
||||
@ -251,7 +250,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Recursive function program: %b\n" (typecheck program)
|
||||
match typecheck program with
|
||||
Ok _ -> Printf.printf "Recursive function program: success\n"
|
||||
| _ -> Printf.printf "Recursive function program: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Scope program *)
|
||||
@ -263,7 +264,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Scope program: %b\n" (typecheck program)
|
||||
match typecheck program with
|
||||
Ok _ -> Printf.printf "Scope program: success\n"
|
||||
| _ -> Printf.printf "Scope program: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Factorial program *)
|
||||
@ -277,8 +280,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Factorial program: %b\n" (typecheck program)
|
||||
;;
|
||||
match typecheck program with
|
||||
Ok _ -> Printf.printf "Factorial program: success\n"
|
||||
| _ -> Printf.printf "Factorial program: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Hailstone sequence's lenght program *)
|
||||
@ -301,8 +305,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Hailstone sequence's lenght program: %b\n" (typecheck program)
|
||||
;;
|
||||
match typecheck program with
|
||||
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 *)
|
||||
@ -323,8 +328,9 @@ let program =
|
||||
)
|
||||
;;
|
||||
|
||||
Printf.printf "Sum multiples of 3 and 5 program: %b\n" (typecheck 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"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Rand program *)
|
||||
@ -337,8 +343,9 @@ let program =
|
||||
|
||||
;;
|
||||
|
||||
Printf.printf "Rand program: %b\n" (typecheck program)
|
||||
;;
|
||||
match typecheck program with
|
||||
Ok _ -> Printf.printf "Rand program: success\n"
|
||||
| _ -> Printf.printf "Rand program: failed\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Fibonacci program *)
|
||||
@ -360,5 +367,6 @@ let program =
|
||||
|
||||
;;
|
||||
|
||||
Printf.printf "Fibonacci program: %b\n" (typecheck program)
|
||||
;;
|
||||
match typecheck program with
|
||||
Ok _ -> Printf.printf "Fibonacci program: success\n"
|
||||
| _ -> Printf.printf "Fibonacci program: failed\n"
|
||||
|
||||
Reference in New Issue
Block a user