FlexibleContexts is under specified
I've been reading the documentation on FlexibleContexts
. It's pretty confusing.
Structure
The documentation is scattered around 3 different sections:
- 9.8.1.2. The superclasses of a class declaration (this is where the link from the flag reference takes you).
- 9.8.3.3. Relaxed rules for instance contexts
- 9.15.2. The context of a type signature
Maybe it's ok to separate it like this, but it took me a while to figure out that there //are// actually three different sections. A simple solution would be to mention that there are 3 different sections, in each section (it already does so in the last section).
Specification
The -XFlexibleContexts flag lifts the Haskell 98 restriction that the type-class constraints in a type signature must have the form
(class type-variable)
or(class (type-variable type1 type2 ... typen))
.
That's all fine and well, but hardly teaches me anything.
I would like to know which type-class constraints //are// allowed with FlexibleContexts
. Or in other words: what is a definition of a "type-class constraint" with FlexibleContexts
?
This is the old grammar:
context → class
| ( class1 , … , classn ) (n ≥ 0)
class → qtycls tyvar
| qtycls ( tyvar atype1 … atypen ) (n ≥ 1)
What is the new one?
Examples
- These are the example mentioned in the section on the context of a class declaration (9.8.1.2):
class Functor (m k) => FiniteMap m k where
class (Monad m, Monad (t m)) => Transform t m where
lift :: m a -> (t m) a
Problem is, they neither require FlexibleContexts
, nor do they compile with FlexibleContexts
!
Those examples require MultiParamTypeClasses
. MultiParamTypeClasses
doesn't enable FlexibleContexts
automatically.
- The section on instance contexts doesn't have any examples.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Documentation |
Test case | |
Differential revisions | |
BlockedBy | |
Related | #12010 (closed) |
Blocking | |
CC | |
Operating system | |
Architecture |