[Haskell-beginners] Custom type classes

Imants Cekusins imantc at gmail.com
Wed Jan 27 08:41:06 UTC 2016


Thank you Guillaume

fun deps are new for me too.

quoting from the above wiki link:


-- Read as: "container" type determines "elem" type.
class Extract container elem | container -> elem where
  extract :: container -> elem
The functional dependency "container -> elem" promises that we won't
declare multiple instances with the same "container" type.



Without the functional dependency, both instances above would be
allowed, and the type of v would be potentially ambiguous. Even if
only one instance is defined, the type system will not figure it out
without the functional dependency.


More information about the Beginners mailing list