[Haskell-beginners] Explicit specification of function types
Tom Poliquin
poliquin at softcomp.com
Mon Mar 23 22:08:28 EDT 2009
Zachary Turner wrote:
> Everything I've read has said that it's generally considered good practice
> to specify the full type of a function before the definition. Why is this?
I'm still a newbie but using (and leaving) the type definitions
helps me quickly recall what a routine is doing and also provides
handy documentation when I have to hack (uhh ... I mean modify)
the code weeks later.
I also agree that when coding having the definitions 'localize'
the type error messages resulting in faster development.
Tom
> It almost seems to go against the principles of type inference. Why let
> the compiler infer types if you're just going to tell it what types to use
> for everything? Ok well, not really for everything, you don't typically
> specify types for local bindings, but still why the inconsistency? I have
> a little experience with ML and F# and there you're encouraged to -not-
> specify types explicitly, and let the compiler infer them for you. In
> fact, it seems like it would be fairly common where you specify a type that
> is -less- general than the type that the compiler would infer for you,
> because the most general type might involve a combination of type classes
> used in various ways, and it may not always be obvious to the programmer
> how to specify it correctly.
More information about the Beginners
mailing list