Basic type classes like Show
, Eq
and Ord
should be easy to grasp by reading the library documentation found by Hoogle and/or Haskell-2010 Language Report.
The numeric tower in Haskell seems to be convoluted (Int
type is an instance of whooping 11 type classes according to the report), but it is just to support all useful kinds of numbers and number representations mathematicians invented for us: e.g. Integer
is a arbitrary size integer, Int
is usual machine word-sized integer, and a lazy Peano representation of integers (not in standard library) proved useful in implementation of graph algorithms. The most important numeric type classes are Num
and Integral
. You can convert between different integer types by using fromIntegral
functions. Note also that numerals such as 123 have type Num a => a
and there's special type defaulting mechanism designed to reduce the need of type declarations to specify exact numeric type you need. In advanced use cases this works against you so you may want to alter the defaults.
The same situation is with different types of strings: no single representation fits all, so many of them are in the wild: String
, Data.ByteString
and Data.Text
are most important.
Regarding more complicated type classes the best source is Typeclassopedia.
For certain type classes such as Monad
, Applicative
and Arrow
there are a lot of dedicated tutorials and research works. Depending on your math skills, you may also want to read original research papers on the category theory concepts behind the type classes such as excellent "Notions of computation and monads" by Eugenio Moggi.
As for "eta reductions" it is called Point-Free Style. You can get some information from
the references mentioned at that link. You can also look at Combinatory Logic, a 1978 paper by John Backus Can programming be liberated from von neumann style? and APL programming language to get a richer historical perspective on the point-free style.
Also there are general books on Haskell such as 'A Gentle Introduction to Haskell' and 'Learn You a Haskell for Great Good'.
As for operator precedence - there are really few operators you must remember: (.)
, ($)
and (>>=)
are used much more than everything else (barring arithmetics of course but arithmetic operators are rather unsurprising).
The syntax for tuples and lists seems unproblematic for me too. It is just redundant: foo : bar : []
is the same as [foo, bar]
and (,) foo bar
is the same as (foo, bar)
. The prefix versions of tuples of higher arity such as (,,,,)
are rarely used.
See also http://www.haskell.org/haskellwiki/Section_of_an_infix_operator for explanation of constructs such as (+ 2)
and (2 +)
called sections.
Also you can learn from the changes the HLint tool suggests to improve your code. The HLint executable can be installed by cabal install HLint
.
As for advanced topics, I can recommend studying purely functional data structures (lets you design efficient immutable data structures and reason about time consumption), call by need lambda calculus (lets you reason about what is evaluated and in which order), System Fc type system (gives you some background on how haskell type checker works), denotational semantic (reasoning about non-termination, partiality and recursion, and also some insight on the notions of strictness, purity and composability).