Due to a bug (unsoundness!) in the typing of assignments, I had to look at how statements are bound. At the moment, Felix binds the body of a function or procedure twice.
The first time, it only looks at return statements, and tries to unify the specified return type, if any, with the return expression. Any unification failure here is tolerated, because it may be that the reason isn't that the types won't unify, but that they won't unify YET. This can happen if there is a recursive dependence on the return type. Once the return type is known, it is cached, and the body is bound again, sometime later. The 'tentative' unification pass can be invoked recursively by another tentative unification pass. The final binding, however, never needs to do this because the return types of all functions are known at this time and must be cached. Ok .. so .. consider: fun f x { var y = 1; y = x; return x; } At present this is an error, because it means: fun f[t] (x:t)=> a; and t is NOT unified to int, because then f wouldn't be parametrically polymorphic. In Ocaml however: let f x = x + 1 does unify the type of x with int. So we can imagine this: fun f(x:infer) { x = 1; } resulting in fun f(x:int) { x = 1; } and the code to make that inference already exists, and is used to infer the return type. It isn't clear how useful this would be, since likely it would be restricted to inference from the function definition and not be allowed to infer from usage. Furthermore because of overloading, many inferences would fail whereas in Ocaml they'd pass due to the lack of it. Suppose we make 'lack of type designation' mean 'infer'. In theory you might have: fun f x y = x + y deduce a constrained polymorphic type: t where Add[t] or even t = int, if there were only one visible function. Hmmm.. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language