[Haskell-beginners] Explicit specification of function types

Zachary Turner divisortheory at gmail.com
Tue Mar 24 00:41:57 EDT 2009


2009/3/23 Brandon S. Allbery KF8NH <allbery at ece.cmu.edu>

> On 2009 Mar 24, at 0:21, Michael Mossey wrote:
>
>> I'm a beginner just learning about type inference (through getting lots of
>> error messages and using :t a lot). I find it fascinating, and it seems a
>> shame to disregard this power by declaring all types. However I realize that
>> it's the more global or critical types that should be declared, and more
>> local areas can be left to inference. Perhaps also the compiler's ability to
>> infer is related to its ability to detect compile-time type errors. In other
>> words, if you program a compiler to be sensitive enough to detect all type
>> errors at compile time, then by necessity you are giving it the smarts to
>> infer types. Is that right?
>>
>
>
> It may have the knowledge but not the mechanism (consider C++).
>

I guess now would be a bad time to mention that C++0x has type inference :D
Off topic, but couldn't resist.  Anyway, back to the original topic (kind
of), would you consider it bad advice to omit type annotations in languages
like ML or F# as well?  I can identify with both arguments, and I just
wonder why one group of people would recommend omitting them, and another
would recommend supplying them, with the only difference being the
language.  I know in something like F# you have a fairly advanced IDE, so
you can simply hover the mouse over a function name and get its inferred
type signature.  I know you mentioned the performance penalty associated
with a type being "too generic", in the sense that typeclass lookups will
constantly have to be done at runtime if something is too generic.  Perhaps
the fact that these other languages don't support typeclasses and hence
don't have the same performance penalty is part of the reason why it's ok
(or at the very least, not as bad) to do this in these languages as it is in
Haskell?

I'm mostly just trying to understand why it's good in one language, and bad
in another.  I'm sure there must be a number of tangible advantages in each
language, that either don't apply or are mapped to disadvantages in the
other.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090323/3e69ce72/attachment-0001.htm


More information about the Beginners mailing list