1
0
Fork 0

fix arg inference

This commit is contained in:
Mylloon 2024-04-30 12:02:14 +02:00
parent 9c41888ec1
commit 5daa03cb1a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -30,7 +30,7 @@ let typeof t =
| _ -> None, env) | _ -> None, env)
| Term.Fun (id, body) -> | Term.Fun (id, body) ->
let arg = TypeSubstitution.singleton id (Type.Var id) in let arg = TypeSubstitution.singleton id (Type.Var id) in
(match infer (TypeSubstitution.compose env arg) body with (match infer (TypeSubstitution.compose arg env) body with
| Some ty_body, env' -> | Some ty_body, env' ->
(match infer env' (Term.Var id) with (match infer env' (Term.Var id) with
| Some ty, _ -> Some (Type.Arrow (ty, ty_body)), env' | Some ty, _ -> Some (Type.Arrow (ty, ty_body)), env'
@ -39,10 +39,14 @@ let typeof t =
| Term.App (t1, t2) -> | Term.App (t1, t2) ->
(* Infer the type of t1 and t2 *) (* Infer the type of t1 and t2 *)
(match infer env t1, infer env t2 with (match infer env t1, infer env t2 with
| (Some (Type.Arrow (ty_param, ty_fn)), _), (Some ty_args, _) -> | (Some (Type.Arrow (ty_param, _)), _), (Some ty_args, _) ->
(* Check if the argument type matches the parameter type *) (* Check if the argument type matches the parameter type *)
(match Unification.unify ty_param ty_args with (match Unification.unify ty_param ty_args with
| Some env' -> Some ty_fn, env' | Some env' ->
(* Infer again now that we have some extra typing infos *)
(match infer env' t1 with
| Some (Type.Arrow (_, ty_fn)), env'' -> Some ty_fn, env''
| _ -> None, env)
| None -> None, env) | None -> None, env)
(* | (Some (Type.Var _ as ty1), _), _ -> (* | (Some (Type.Var _ as ty1), _), _ ->
(* On this case we may have a function represented as a variable *) (* On this case we may have a function represented as a variable *)