This commit is contained in:
Pierre-Emmanuel Wulfman 2020-04-29 19:39:46 +02:00
parent 2c62f9d32e
commit 8d59389f7d
2 changed files with 6 additions and 3 deletions

View File

@ -342,7 +342,8 @@ and eval : Ast_typed.expression -> env -> value result
let {hd;tl;body;tv=_} = cases.match_cons in let {hd;tl;body;tv=_} = cases.match_cons in
let env' = Env.extend (Env.extend env (hd,head)) (tl, V_List tail) in let env' = Env.extend (Env.extend env (hd,head)) (tl, V_List tail) in
eval body env' eval body env'
| Match_variant {cases=[{constructor=Constructor "true";body=match_true};{constructor=Constructor "false"; body=match_false}];_}, V_Ct (C_bool b) -> | Match_variant {cases=[{constructor=Constructor t;body=match_true};{constructor=Constructor f; body=match_false}];_}, V_Ct (C_bool b)
when String.equal t "true" && String.equal f "false" ->
if b then eval match_true env if b then eval match_true env
else eval match_false env else eval match_false env
| Match_variant {cases ; tv=_} , V_Construct (matched_c , proj) -> | Match_variant {cases ; tv=_} , V_Construct (matched_c , proj) ->

View File

@ -580,7 +580,8 @@ and transpile_annotated_expression (ae:AST.expression) : expression result =
in in
return @@ E_if_cons (expr' , nil , cons) return @@ E_if_cons (expr' , nil , cons)
) )
| Match_variant {cases=[{constructor=Constructor "true";body=match_true};{constructor=Constructor "false";body=match_false}];_} -> | Match_variant {cases=[{constructor=Constructor t;body=match_true};{constructor=Constructor f;body=match_false}];_}
when String.equal t "true" && String.equal f "false" ->
let%bind (t , f) = bind_map_pair (transpile_annotated_expression) (match_true, match_false) in let%bind (t , f) = bind_map_pair (transpile_annotated_expression) (match_true, match_false) in
return @@ E_if_bool (expr', t, f) return @@ E_if_bool (expr', t, f)
| Match_variant {cases ; tv} -> ( | Match_variant {cases ; tv} -> (
@ -703,7 +704,8 @@ and transpile_recursive {fun_name; fun_type; lambda} =
in in
return @@ E_if_cons (expr , nil , cons) return @@ E_if_cons (expr , nil , cons)
) )
| Match_variant {cases=[{constructor=Constructor "true";body=match_true};{constructor=Constructor "false";body=match_false}];_} -> | Match_variant {cases=[{constructor=Constructor t;body=match_true};{constructor=Constructor f;body=match_false}];_}
when String.equal t "true" && String.equal f "false" ->
let%bind (t , f) = bind_map_pair (replace_callback fun_name loop_type shadowed) (match_true, match_false) in let%bind (t , f) = bind_map_pair (replace_callback fun_name loop_type shadowed) (match_true, match_false) in
return @@ E_if_bool (expr, t, f) return @@ E_if_bool (expr, t, f)
| Match_variant {cases;tv} -> ( | Match_variant {cases;tv} -> (