Better styling for miniFun
This commit is contained in:
@ -5,14 +5,17 @@ Random.self_init ()
|
|||||||
|
|
||||||
let (let*) = Result.bind
|
let (let*) = Result.bind
|
||||||
|
|
||||||
let rec evaluate (mem: memory) (command: t_exp) : (permittedValues, [> error]) result =
|
let rec evaluate (mem: memory) (command: t_exp) :
|
||||||
|
(permittedValues, [> error]) result =
|
||||||
match command with
|
match command with
|
||||||
Integer n -> Ok (IntegerPermitted n)
|
Integer n -> Ok (IntegerPermitted n)
|
||||||
| Boolean b -> Ok (BooleanPermitted b)
|
| Boolean b -> Ok (BooleanPermitted b)
|
||||||
| Variable v -> (
|
| Variable v -> (
|
||||||
match VariableMap.find_opt v mem.assignments with
|
match VariableMap.find_opt v mem.assignments with
|
||||||
None -> Error (`AbsentAssignment ("The variable " ^ v ^ " is not defined."))
|
| None ->
|
||||||
| Some a -> Ok a
|
Error (`AbsentAssignment ("The variable " ^ v ^ " is not defined."))
|
||||||
|
| Some a ->
|
||||||
|
Ok a
|
||||||
)
|
)
|
||||||
| Tuple (x, y) -> (
|
| Tuple (x, y) -> (
|
||||||
let* xval = evaluate mem x in
|
let* xval = evaluate mem x in
|
||||||
|
|||||||
@ -5,7 +5,8 @@ Random.self_init ()
|
|||||||
|
|
||||||
let (let*) = Result.bind
|
let (let*) = Result.bind
|
||||||
|
|
||||||
let rec evaluate_type (program: t_exp) (context: ftype VariableMap.t) : (ftype, [> typechecking_error]) result =
|
let rec evaluate_type (program: t_exp) (context: ftype VariableMap.t) :
|
||||||
|
(ftype, [> typechecking_error]) result =
|
||||||
match program with
|
match program with
|
||||||
Integer _ -> Ok IntegerType
|
Integer _ -> Ok IntegerType
|
||||||
| Boolean _ -> Ok BooleanType
|
| Boolean _ -> Ok BooleanType
|
||||||
@ -25,7 +26,8 @@ let rec evaluate_type (program: t_exp) (context: ftype VariableMap.t) : (ftype,
|
|||||||
the type of the body using the bindings for the input *)
|
the type of the body using the bindings for the input *)
|
||||||
match typef with
|
match typef with
|
||||||
FunctionType (tin, tout) -> (
|
FunctionType (tin, tout) -> (
|
||||||
let* typefbody = evaluate_type fbody (VariableMap.add x tin context) in
|
let* typefbody = evaluate_type fbody (VariableMap.add x tin context)
|
||||||
|
in
|
||||||
if (typefbody = tout) then
|
if (typefbody = tout) then
|
||||||
Ok typef
|
Ok typef
|
||||||
else
|
else
|
||||||
|
|||||||
@ -35,7 +35,8 @@ type t_exp =
|
|||||||
| CmpGreaterEq of t_exp * t_exp (* x >= x *)
|
| CmpGreaterEq of t_exp * t_exp (* x >= x *)
|
||||||
| IfThenElse of t_exp * t_exp * t_exp (* if b then c else c *)
|
| IfThenElse of t_exp * t_exp * t_exp (* if b then c else c *)
|
||||||
| LetIn of variable * t_exp * t_exp (* let x = x in x *)
|
| LetIn of variable * t_exp * t_exp (* let x = x in x *)
|
||||||
| LetFun of variable * variable * ftype * t_exp * t_exp (* let rec x. y: t. x in x*)
|
| LetFun of variable * variable * ftype * t_exp * t_exp
|
||||||
|
(* let rec x. y: t. x in x*)
|
||||||
|
|
||||||
type permittedValues =
|
type permittedValues =
|
||||||
IntegerPermitted of int
|
IntegerPermitted of int
|
||||||
|
|||||||
Reference in New Issue
Block a user