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 <[email protected]>

> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to