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

Simon Peyton-Jones simonpj at microsoft.com
Mon May 21 05:36:00 EDT 2007


| 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'".

That's a bug.  b should be in scope


However, your program is very suspicious!  Associated data types *replace* functional dependencies, so you should not use both.  Your probably want something like

        class G a where
          data E a :: *
          wrap :: a -> E a
          unwrap :: E a -> a

Simon


More information about the Haskell-Cafe mailing list