[Haskell-cafe] Re: Scope of type variables in associated types

Matthew Sackman matthew at wellquite.org
Sat May 19 19:53:52 EDT 2007


On Sat, May 19, 2007 at 08:40:46PM +0100, Matthew Sackman wrote:
> The following doesn't seem to work. Is this a limitation of the current
> implementation or will it never work? Are there any work arounds without
> introducing extra type params into the data type E?
> 
> > class G a b | a -> b where
> >     data E a :: *
> >     wrap :: b -> E a
> >     unwrap :: E a -> b
> 
> > instance G a b where
> >     data E a = EC b -- this line - the b is not in scope.
> >     wrap = EC
> >     unwrap (EC b) = b
> 
> I get "Not in scope: type variable `b'". I was rather hoping it would be
> in scope.

Having thought about this for some time, I think I can see a reason that
this might not be possible.

Classes are open, thus the a -> b does not ensure that there will
only ever be one E a for each unique a in G a b, given multiple modules.

>From the paper [0], pg 10:

   "We could also in principle allow an associated type to mention only
   a subset of its parent class parameters; but then we would need to
   make extra tests to ensure the instance declarations did not overlap
   taking into account only the selected class parameters to ensure the
   type translation described by \Omega is confluent."

Well, I suppose that given the open type classes, the instance
declarations can overlap, despite the fundep. Does this mean that until
we get closed classes, this sort of thing is impossible (without ugly
workarounds)?

Any thoughts at all? Anyone? Is it the case that associated types really
allow nothing that can't be done with fundeps?

[0] "Associated Types with Class"
    http://www.cse.unsw.edu.au/~chak/papers/CKPM05.html

Matthew
-- 
Matthew Sackman
http://www.wellquite.org/


More information about the Haskell-Cafe mailing list