[GHC] #12121: FlexibleContexts is under specified

#12121: FlexibleContexts is under specified -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Documentation | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Documentation Unknown/Multiple | bug Test Case: | Blocked By: Blocking: | Related Tickets: #12010 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- 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 [http://downloads.haskell.org/~ghc/8.0.1/docs/html/users_guide/glasgow_exts.h... #ghc-flag--XFlexibleContexts 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. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12121 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12121: FlexibleContexts is under specified -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Documentation | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #12020 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * related: #12010 => #12020 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12121#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12121: FlexibleContexts is under specified -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Documentation | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #12020 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): That's bad. Would you be willing to fix it if I tell you the specification?
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?
With `FlexibleContexts` you can put anything `Constraint`-kinded in the context. Except * For class decls, no implicit parameters * For instance decls, no implicit parameters, and must be smaller than the head unless `UndecidableInstances`. For contexts in type signatures Haskell 98 allowed `Functor (m k)`, or even `Functor (m [k])`; anything headed by a tyvar, as in the syntax for `context` above. But the Haskell 98 report is more restrictive for class decls; they are supposed to be `cls tyvar`. Alas, GHC does not do this; it treats them the same as type signatures. Henc, yes, {{{ class Functor (m k) => FiniteMap m k where }}} does not require `FlexibleContexts`. (It does compile with `FlexibleContexts` though, doesn't it?) I don't know whether it is worth tightening this up. Does that help? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12121#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12121: FlexibleContexts is under specified -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: bug | Status: new Priority: normal | Milestone: Component: Documentation | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #12020 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * owner: => thomie -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12121#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12121: FlexibleContexts is under specified -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: bug | Status: new Priority: normal | Milestone: Component: Documentation | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #12120 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * related: #12020 => #12120 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12121#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12121: FlexibleContexts is under specified -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: bug | Status: new Priority: normal | Milestone: Component: Documentation | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Documentation | Unknown/Multiple bug | Test Case: Blocked By: | Blocking: Related Tickets: #12120 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * cc: mpickering (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12121#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC