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

Matthew Brecknell haskell at brecknell.org
Mon May 21 21:19:25 EDT 2007


Bertram Felgenhauer:
> How does
> 
>   class F a where
>       data B a :: *
>       data E a :: *
>       wrap :: B a -> E a
>       unwrap :: E a -> B a
> 
> sound? 'B a' would represent the 'b' in your previous attempt,
> 
>   class F a b | a -> b where
>   ...
> 

I'm with Simon in thinking that this code is suspicious.

For any given call to "wrap" or "unwrap", how is the compiler supposed
to determine which instance to use, given that "a" cannot be uniquely
determined from the type of the function? The same question also applies
to Matthew's original formulation using functional dependencies:

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

Simon's reformulation doesn't have this problem:

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



More information about the Haskell-Cafe mailing list