Better styling for miniImp
This commit is contained in:
@ -53,8 +53,10 @@ and evaluate_a (mem: memory) (exp_a: a_exp) : (int, [> error]) result =
|
||||
match exp_a with
|
||||
Variable v -> (
|
||||
match VariableMap.find_opt v mem.assignments with
|
||||
None -> Error (`AbsentAssignment ("The variable " ^ v ^ " is not defined."))
|
||||
| Some a -> Ok a
|
||||
| None ->
|
||||
Error (`AbsentAssignment ("The variable " ^ v ^ " is not defined."))
|
||||
| Some a ->
|
||||
Ok a
|
||||
)
|
||||
| Integer n -> Ok n
|
||||
| Plus (exp_a1, exp_a2) -> (
|
||||
@ -148,9 +150,13 @@ and evaluate_b (mem: memory) (exp_b: b_exp) : (bool, [> error]) result =
|
||||
let reduce (program: p_exp) (iin : int) : (int, [> error]) result =
|
||||
match program with
|
||||
Main (vin, vout, expression) -> (
|
||||
let mem : memory = {assignments = (VariableMap.empty |> VariableMap.add vin iin)} in
|
||||
let mem : memory =
|
||||
{ assignments = (VariableMap.empty |> VariableMap.add vin iin) } in
|
||||
let* resultmem : memory = evaluate mem expression in
|
||||
match VariableMap.find_opt vout resultmem.assignments with
|
||||
None -> Error (`AbsentAssignment ("The output variable is not defined (" ^ vout ^ ")"))
|
||||
| Some a -> Ok a
|
||||
| None ->
|
||||
Error (`AbsentAssignment
|
||||
("The output variable is not defined (" ^ vout ^ ")"))
|
||||
| Some a ->
|
||||
Ok a
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user