[Haskell-beginners] More type errors I'm having trouble with

Thomas Koster tkoster at gmail.com
Tue Dec 8 03:53:51 UTC 2015


On 4 December 2015 at 08:58, Dan Stromberg <strombrg at gmail.com> wrote:
> I read somewhere (probably Learn You a Haskell or Real-World Haskell) that
> beginners should use a lot of type declarations, but perhaps that's not a
> great idea after all.

I agree. Excessive type signatures makes code harder to read, less
"beautiful" (yes, Haskell code can be beautiful), and increases the
surface area for bugs, typos and other mistakes.

Type inference in Haskell is an excellent aid for beginners and pros
alike, and beginners should learn to feel comfortable with it. Haskell
style commentators generally agree that type signatures for top-level
bindings are a good thing, but they should be used sparingly
everywhere else.

If you are using GHC, I have also found that temporarily removing some
top-level type signatures and compiling with -Wall may give you some
new insights into your functions. GHC warns you about the missing
signatures and tells you what it infers, which may be more
general/polymorphic than the type you originally entered. This can
help greatly to spot polymorphic functions, reduce code duplication
and find places where you can use folds and traversals from the
standard library (Data.Foldable, Data.Traversable, etc.).

--
Thomas Koster


More information about the Beginners mailing list