[Haskell-cafe] Solved but strange error in type inference
allbery.b at gmail.com
Tue Jan 3 12:49:19 CET 2012
On Tue, Jan 3, 2012 at 06:43, Yves Parès <limestrael at gmail.com> wrote:
> 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
> 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?
Yep, with the additional gotcha that two uses of the same data constructor
in an expression will not unify those type variables because it's scoped to
the data constructor itself. Which is the confusing and error-prone
behavior that led to it being removed from the next version of the standard
(probably; the proposal was accepted but H'2011 was bypassed and H'2012 has
not yet started).
brandon s allbery allbery.b at gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe