From 0ec66864fbc5ce4cf5c628602be813b60dab3bd7 Mon Sep 17 00:00:00 2001 From: Nicolas PENELOUX Date: Tue, 5 Dec 2023 19:16:35 +0100 Subject: [PATCH] =?UTF-8?q?Fields=20(marche=20pas),=20d=C3=A9but=20pattern?= =?UTF-8?q?,=20Tuple=20et=20Fun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flap/src/hopix/hopixTypechecker.ml | 46 ++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/flap/src/hopix/hopixTypechecker.ml b/flap/src/hopix/hopixTypechecker.ml index 7114d34..7bcb070 100644 --- a/flap/src/hopix/hopixTypechecker.ml +++ b/flap/src/hopix/hopixTypechecker.ml @@ -90,8 +90,16 @@ and synth_pattern : HopixTypes.typing_environment -> HopixAST.pattern Position.located -> HopixTypes.aty * HopixTypes.typing_environment = - fun env Position.{ value = p; position = pos } -> - failwith "Students! This is your job! (synth_pattern)" + fun env Position.{ value = p; position = pos } -> match p with + | PWildcard -> failwith "PWildcard" + | PLiteral l-> failwith "Pliteral" + | PVariable pv -> failwith "PVariable" + | PTypeAnnotation(p,ty) -> failwith "PTypeAnnot" + | PTuple(plist) -> failwith "PTuple" + | POr(plist) -> failwith "POr" + | PAnd (plist) -> failwith "PAnd" + | PTaggedValue(cons,tlist,plist) -> failwith "PTagged" + | PRecord(plist,tlist) -> failwith "PRecord" and synth_variable : HopixTypes.typing_environment -> identifier Position.located @@ -206,7 +214,10 @@ and synth_fun : HopixTypes.typing_environment -> pattern Position.located -> expression Position.located -> HopixTypes.aty = - fun tenv pat expr -> failwith "Students! This is your job! (synth_fun)" + fun tenv pat expr -> + let pat_type, tenv = synth_pattern tenv pat in + let expr_type = synth_expression tenv expr in + ATyArrow(pat_type,expr_type) and synth_tannot : HopixTypes.typing_environment -> expression Position.located -> ty Position.located @@ -222,12 +233,35 @@ and synth_field : HopixTypes.typing_environment -> expression Position.located -> label Position.located -> ty Position.located list option -> HopixTypes.aty = - fun tenv expr lbl tlist -> failwith "Students! This is your job! (synth_field)" - + fun tenv expr lbl tlist -> failwith "synth_field" (*let expr_type = synth_expression tenv expr in + match expr_type with + | ATyCon(cons,atlist) -> + ( + (* Impossible car n'est pas dans le mli*) + let lbllist = HopixTypes.lookup_information_of_type_constructor lbl.position cons tenv in + match lbllist with + | Record r -> + if List.mem lbl.value r + then + let label_scheme = + try HopixTypes.lookup_type_scheme_of_label label_pos label_val tenv with + | HopixTypes.Unbound (pos, Label (LId i)) -> + HopixTypes.type_error pos (Printf.sprintf "Unbound label `%s'." i) + in + try HopixTypes.instantiate_type_scheme label_scheme atlist with + | HopixTypes.InvalidInstantiation { expected; given } -> + invalid_instantiation (Position.position expr) expected given + else + failwith "Erreur de label" + ) + | _ -> failwith "Ceci n'est pas un label" +*) and synth_tuple : HopixTypes.typing_environment -> expression Position.located list -> HopixTypes.aty = - fun tenv elist -> failwith "Students! This is your job! (synth_tuple)" + fun tenv elist -> let list_type = List.map( + fun x -> synth_expression tenv x + ) elist in HopixTypes.ATyTuple(list_type) and synth_sequence : HopixTypes.typing_environment -> expression Position.located list -> HopixTypes.aty