aboutsummaryrefslogtreecommitdiff
path: root/evaluator.ml
diff options
context:
space:
mode:
Diffstat (limited to 'evaluator.ml')
-rwxr-xr-xevaluator.ml14
1 files changed, 10 insertions, 4 deletions
diff --git a/evaluator.ml b/evaluator.ml
index 4bbf780..b390771 100755
--- a/evaluator.ml
+++ b/evaluator.ml
@@ -388,7 +388,7 @@ let f_number: DataType.Num.t Data.result = Data.Number
let f_string: DataType.String.t Data.result = Data.String
let f_bool: DataType.Bool.t Data.result = Data.Bool
-module MAKE(C: D.COMPARABLE) = struct
+module Make_Compare(C: D.COMPARABLE) = struct
let register t = begin
register2 "=" (t, t) f_bool C.eq;
@@ -423,10 +423,12 @@ let fold name t_in t_out f init = begin
List.fold_left (List.fold_left f) init x);
end
+let if_: type a. bool -> a -> a -> a = fun a b c -> if a then b else c
+
let () = begin
- let module CompareNum = MAKE(D.Num) in
+ let module CompareNum = Make_Compare(D.Num) in
Data.(
CompareNum.register t_int;
register0 "rand" f_number D.Num.rnd;
@@ -439,6 +441,10 @@ let () = begin
register2 "/" (t_int, t_int) f_number D.Num.div;
register2 "^" (t_int, t_int) f_number D.Num.pow;
+ register3 "if" (t_bool, t_int, t_int) f_number if_;
+ register3 "if" (t_bool, t_bool, t_bool) f_bool if_;
+ register3 "if" (t_bool, t_string, t_string) f_string if_;
+
register1 "abs" t_int f_number D.Num.abs;
fold "sum" t_int f_number D.Num.add (D.Num.of_num (Num.num_of_int 0));
@@ -447,7 +453,7 @@ let () = begin
reduce "min" t_int f_num D.Num.min; (* Minimum value from a list *)
reduce "max" t_int f_num D.Num.max; (* Maximum value from a list *)
- let module CompareBool = MAKE(D.Bool) in
+ let module CompareBool = Make_Compare(D.Bool) in
CompareBool.register t_bool;
register0 "true" f_bool (fun () -> D.Bool.true_);
register0 "false" f_bool (fun () -> D.Bool.false_);
@@ -456,7 +462,7 @@ let () = begin
register2 "or" (t_bool, t_bool) f_bool D.Bool.or_;
register2 "xor" (t_bool, t_bool) f_bool D.Bool.neq;
- let module CompareString = MAKE(D.String) in
+ let module CompareString = Make_Compare(D.String) in
CompareString.register t_string;
(* Build a date *)