On Sun, Jan 06, 2008 at 11:15:12PM -0800, SJS wrote:
But it also seems to open the door for auto-return-types.
This is what you get with full Hindley-Milner type-inference. It is possible to write large, complex programs, without ever declaring what types things are, and yet the language is fully statically typed. Inferring variable types isn't that hard. Inferring return types isn't that hard. Inferring both is quite complicated. It defines a dependency graph that has to propagate knowledge until the graph is either complete, or there is a conflict. It also requires type variables, since there might be parts of a type that just aren't known. E.g. (in something resembling Haskell) map f [] = [] map f (x:r) = (f x) : (map f r) It allows patterns at the top level as basically a case statement. The first line says that map (with two arguments) if the second argument is an empty list, return an empty list. The second line says to split apart the first item from the rest of the list, call f with that argument, and stick that on the beginning of a new list which recursively invokes map on the rest of the list. The complier figures out it's type as: map :: (a -> b) -> [a] -> [b] which basically means the first argument is a function taking some type 'a', and returning some type 'b'. The second argument is a list of type 'a', and the function returns a list of type 'b'. Map doesn't care what 'a' and 'b' are, but for a given inference, all of the 'a's must map to the same type, and all of the 'b's to the same type. Dave -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
