logo       

RE: Using implicit parameter constraints in data decl: msg#00018

lang.haskell.glasgow.bugs

Subject: RE: Using implicit parameter constraints in data decl

OK, this is a bug in GHC 6.2.2. The definition is rejected tidily by
the HEAD, on the grounds that, in general, record selectors are
ill-typed for existentials. For example
data T = forall a. MkT { x::a, f::a->Int }
The selectors for 'x' or 'f' would both be ill typed.

In this case, though, the 'existential' context is only a monomorphic
implicit parameter, so there's no danger of capturing an existential
type variable; so I'm going to arrange to allow it, so that
data T a = (?val::Int) => MkT a
will be OK.

Meanwhile a second and unrelated bug in 6.2.2 also blows up for
data Test = (?val::Bool) => Test String
This time it's because GHC tries to generate to/from functions for
'derivable type classes', when it's actually too complex for that.
Again, the HEAD is fine. A workaround is to use -fno-generics.


I don't plan to fix either of these on the 6.2 branch, because we don't
plan another 6.2 release.

Thanks for finding these. I'll add them to the test suite.

Simon

| -----Original Message-----
| From: Benjamin Franksen [mailto:benjamin.franksen@xxxxxxxx]
| Sent: 07 November 2004 18:37
| To: Simon Peyton-Jones
| Cc: glasgow-haskell-bugs@xxxxxxxxxxx; haskell@xxxxxxxxxxx
| Subject: Re: Using implicit parameter constraints in data decl
|
| On Sunday 07 November 2004 20:09, Simon Peyton-Jones wrote:
| | Definitely a bug. Could you pls make a small module that elicits
the
| | bug, and send it to me?
|
| Here it is:
|
| > module Test where
| >
| > data Test = (?val::Bool) => Test { name :: String }
| >
| > instance Show Test where
| > show p = name p
|
| franksen@linux: .../src/testbug > ghc -fimplicit-params TestBug.hs
| ghc-6.2.2: panic! (the `impossible' happened, GHC version 6.2.2):
| simplCore/Simplify.lhs:1473: Non-exhaustive patterns in
function
| cat_evals
|
| BTW, I see now that the data declaration is syntactically wrong.
Anyway, the
| (syntactically) correct version
|
| data (?val::Bool) => Test = Test { name :: String }
|
| is rejected by the compiler:
|
| TestBug.hs:3:
| Illegal constraint ?val :: Bool
| In the context: (?val :: Bool)
| While checking the context of the data type declaration for `Test'
| In the data type declaration for `Test'
|
| which is unfortunate since it means that you cannot put a function
that
| depends on an implicit parameter into a data structure. There are
probably
| technical reasons for this restriction, but it means that such
functions are
| no longer first class objects.
|
| Cheers,
| Ben


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise