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

Brandon Allbery 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
> 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?


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...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120103/0a83a65e/attachment.htm>


More information about the Haskell-Cafe mailing list