Hi, thank you for interesting implementations.
These type systems are implemented for tiny language. It contains Var, Call, Fun and Let expressions. While reading your algorithm_w implementation, I noticed that they lack important functional programming feature: recursive functions.
For recursive functions, type inference sometimes needs to care about them. Before applying type inference, type variable for the function should be added to type environment because function body may contain applying itself (recursive call).
For example, assume let rec exists and let's say to write let rec f x = f 10; 42 in f true. When visiting the LetRec node, inferrer makes type variable for f to type environment before apply type analysis to function body f 10; 42 for recursive function call. And then applies type inference to f 10. In function body, the type of f is determined to int -> int. This works for monomorphic function. But in this case, f is a polymorphic function 'a -> int. But function type is determined before generalized. Hence f true will fail after because of int -> int type. I feel some trick is necessary to support recursive function. What do you think about this?
Hi, thank you for interesting implementations.
These type systems are implemented for tiny language. It contains
Var,Call,FunandLetexpressions. While reading youralgorithm_wimplementation, I noticed that they lack important functional programming feature: recursive functions.For recursive functions, type inference sometimes needs to care about them. Before applying type inference, type variable for the function should be added to type environment because function body may contain applying itself (recursive call).
For example, assume
let recexists and let's say to writelet rec f x = f 10; 42 in f true. When visiting theLetRecnode, inferrer makes type variable forfto type environment before apply type analysis to function bodyf 10; 42for recursive function call. And then applies type inference tof 10. In function body, the type offis determined toint -> int. This works for monomorphic function. But in this case,fis a polymorphic function'a -> int. But function type is determined before generalized. Hencef truewill fail after because ofint -> inttype. I feel some trick is necessary to support recursive function. What do you think about this?