On Fri, Jan 04, 2008 at 01:34:10AM -0800, Chuck Esterbrook wrote:
I like what Hindley-Milner type-inference brings, but it has it's
disadvantages, too, such as very cryptic error messages.
Not clear if you guys already noticed this, but Cobra supports *both*.
The first language I encountered such support in was Objective-C and I
liked it a lot.
I don't think you do Hindley-Milner type-inference. You infer types of
variables so that they don't have to be declared. That's quite a bit less
than H-M, which does type inference of _everything_, with polymorphism and
lots of nifty stuff.
As an example, the List.map function in ocaml has a type signature of:
('a -> 'b) -> 'a list -> 'b list
which means it takes as a first argument a function mapping an arbitrary
type 'a' to another arbitrary type 'b'. It's second argument must be a
list of whatever 'a' is and returns a list of 'b'. Map is implemented as:
let rec map f = function
[] -> []
| a:: -> let r = f a in r :: map f l
it's isn't that important what the syntax means, but just that it isn't
necessary to specify the type. It figures out the necessary type of the
function based on how all of the arguments are used.
Most simple type-inference uses knowledge of return results to determine
other types. H-M works in both directions (it also infers return results)
reducing in both directions until it has an unambiguous result, or it is
left with a set of anonymous types, which it then just uses as the
signature.
Dave
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg