[Haskell-cafe] Solved but strange error in type inference

Yves Parès limestrael at gmail.com
Tue Jan 3 12:43:41 CET 2012


That is error-prone.
Plus the code does not need ScopedTypeVariables. The real problem comes
from the use of a class constraint on the LegGram data constructor.

data LegGram nt t s = Ord nt => LegGram (M.Map nt [RRule nt t s])

Short answer: you *can't *add class constraints to an already declared type
variable:

The LegGram *type *constructor declares the 'nt' variable (and then brings
it into scope), so trying afterwards to add a constraint to it for the
LegGram *data *constructor is invalid, so the compiler understands this:
data LegGram nt t s = *forall nt.* Ord nt => LegGram (M.Map *nt*
[RRule *nt*t s])
...the declaration and scoping of a *new* type variable.

This is it, right?

2012/1/3 Yucheng Zhang <yczhang89 at gmail.com>

> As I understand it, both ways work.
>
> > legSome ((LegGram g)::LegGram nt t s) ntV
>
> If you compile this without ScopedTypeVariables extension, GHC will
> remind you of it:
>
> >    Illegal signature in pattern: LegGram nt t s
> >        Use -XScopedTypeVariables to permit it
>
> So another solution is to avoid the ugly redundancy is:
>
> > legSome :: forall nt t s . LegGram nt t s -> nt -> Either String ([t], s)
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120103/023d5edc/attachment.htm>


More information about the Haskell-Cafe mailing list