[Haskell-cafe] Re: FlexibleContexts and FlexibleInstances

Claus Reinke claus.reinke at talk21.com
Thu Jun 11 04:16:33 EDT 2009


|What you describe is exactly how I would *want* things to work. It's
|nice to hear my wishes echoed from a user perspective. :-)

actually, I was describing how things seem to work right now.

|> Only MultiParamTypeClasses does (and neither extension is needed in the
|> module defining 'f', if 'T' is imported, which suggests that
|> MultiParamTypeClasses is propagated to importers - this isn't true for
|> most other extensions). The documentation still points to -fglasgow-exts, so
|> it doesn't seem to answer these questions..
|
|Right you are - which seems very strange to me. GHC accepts the module
|defining 'f' with no flags at all, even though it is clearly not
|Haskell 98. I'd go so far as to say that's a bug (as opposed to just
|unwanted/unexpected behavior).

It is not that strange, really (it ought to be documented, but the fan-
out from glasgow-exts/hugs mode to more detailed extensions has
been fairly recent, compared to the lifetime of these features):

if module 'A' exports multiparameter type classes, importers of those
classes have to have MultiParamTypeClasses on - there are no legal
uses of those imports otherwise (while FlexibleInstances/Contexts can
just affect a subset of use sites).

|> No. FlexibleInstances is about instance *heads*, FlexibleContexts is about
|> contexts everywhere (in practice, there are some bugs;-).
|
|Right, this is exactly what I *want* should happen, both as a user and
|as an implementor, but that's not how GHC does it. FlexibleInstances
|do enable FlexibleContexts for contexts in instance declarations -
|which I think is a wart.
|
|> class T a b -- requires MultiParamTypeClasses instance T a a -- requires
|> FlexibleInstances instance Eq () => T a [b] -- requires FlexibleContexts
|> instance Eq [a] => T a b -- requires UndecidableInstances

Perhaps I should have been more explicit, but if you try that example
by adding one line after the other, starting from zero extensions, you'll 
find that FlexibleInstances does not enable FlexibleContexts (at least not 
in my versions of GHC, which always stop at the first class of language 
errors and force me into an iterative cycle of code, error, add one 
pragma, error, add another pragma, ..).

Claus




More information about the Glasgow-haskell-users mailing list