synth_case
This commit is contained in:
parent
e8c6f8da9b
commit
f9c8d3e2f9
1 changed files with 20 additions and 1 deletions
|
@ -444,11 +444,30 @@ and synth_read
|
||||||
let refty = synth_expression tenv ref in
|
let refty = synth_expression tenv ref in
|
||||||
HopixTypes.destruct_reference_type ref.position refty
|
HopixTypes.destruct_reference_type ref.position refty
|
||||||
|
|
||||||
|
and synth_branch
|
||||||
|
: HopixTypes.typing_environment -> HopixTypes.aty -> branch Position.located
|
||||||
|
-> HopixTypes.aty option -> HopixTypes.aty option
|
||||||
|
=
|
||||||
|
fun tenv casety branch branchty ->
|
||||||
|
let (Branch (p, e)) = branch.value in
|
||||||
|
let given_case, tenv' = synth_pattern tenv p in
|
||||||
|
check_equal_types p.position ~expected:casety ~given:given_case;
|
||||||
|
let given_branch = synth_expression tenv' e in
|
||||||
|
(match branchty with
|
||||||
|
| None -> ()
|
||||||
|
| Some ty' -> check_equal_types e.position ~expected:ty' ~given:given_branch);
|
||||||
|
Some given_branch
|
||||||
|
|
||||||
and synth_case
|
and synth_case
|
||||||
: HopixTypes.typing_environment -> expression Position.located
|
: HopixTypes.typing_environment -> expression Position.located
|
||||||
-> branch Position.located list -> HopixTypes.aty
|
-> branch Position.located list -> HopixTypes.aty
|
||||||
=
|
=
|
||||||
fun tenv expr branches -> failwith "Students! This is your job! (synth_case)"
|
fun tenv expr branches ->
|
||||||
|
let casety = synth_expression tenv expr in
|
||||||
|
(* Test les branches *)
|
||||||
|
match List.fold_right (synth_branch tenv casety) branches None with
|
||||||
|
| Some branchesty -> branchesty
|
||||||
|
| None -> HopixTypes.type_error expr.position "No types found."
|
||||||
|
|
||||||
and synth_ifthenelse
|
and synth_ifthenelse
|
||||||
: HopixTypes.typing_environment -> expression Position.located
|
: HopixTypes.typing_environment -> expression Position.located
|
||||||
|
|
Reference in a new issue