The vertical bar is a syntactic separator that has no meaning and is used to introduce functional dependencies into a class with several parameters, therefore technically | does not mean anything. Presumably | was chosen as a visual analogy with the same symbol as for template templates for functions.
As for the functional dependencies themselves, just read x -> y , because "a parameter of type x uniquely defines a parameter of type y ", which means that knowing only x enough to find the correct instance. There are other complications, especially with the GHC extensions enabled, but most of the time you don't need to worry about them.
In contrast, without functional dependencies, selecting an instance of a class with several parameters requires that all parameters of the type be known. A typical example has one parameter, which is the type of container, and the second is the type of contained elements; functions such as "concatenate" or "isEmpty" should not mention the type of element, only the type of container and, therefore, will be ambiguous.
Also, if you are writing your own type classes, use family types instead, which are a new approach that may eventually replace functional dependencies. Roughly speaking, family types allow you to write overloaded type definitions within an instance, and not just overloaded functions.
CA McCann Apr 20 '10 at 14:21 2010-04-20 14:21
source share