Type synonym family inside type class

Hello, I have a type family and a type class:
type family ErrorAlg (f :: (* -> *) -> * -> *) e ix :: *
class MkErrorAlg f where mkErrorAlg :: ErrorAlg f e a -> f (K0 a) ix -> Either e a
Instances for these two really go hand in hand, so I thought I would move the type family into the type class. However, this causes GHC to complain about the type variables that are bound on the LHS of the type synonym:
Not in scope: type variable `e' Not in scope: type variable `ix'
In function types, using new type variables (i.e. type variables not bound by the type class header) implicitly means universal quantification over these variables. Why is this disallowed in type families inside type classes? Thanks, Martijn.

I have a type family and a type class:
type family ErrorAlg (f :: (* -> *) -> * -> *) e ix :: *
class MkErrorAlg f where
mkErrorAlg :: ErrorAlg f e a -> f (K0 a) ix -> Either e a
Instances for these two really go hand in hand, so I thought I would move the type family into the type class.
Perhaps this isn't answering your question, but you can turn the above into an associated type as follows. class MkErrorAlg f where
type ErrorAlg (f :: (* -> *) -> * -> *) :: * -> * -> * mkErrorAlg :: ErrorAlg f e a -> f (K0 a) ix -> Either e a
Regards, Sean

Hi Sean, Sean Leather wrote:
Perhaps this isn't answering your question, but you can turn the above into an associated type as follows.
class MkErrorAlg f where type ErrorAlg (f :: (* -> *) -> * -> *) :: * -> * -> * mkErrorAlg :: ErrorAlg f e a -> f (K0 a) ix -> Either e a
That is true. But how would you translate the following instance to the new version?
type instance ErrorAlg (K b :*: f) e a = b -> ErrorAlg f e a
I don't know how to do that without introducing a new newtype that I can partially parametrize. I don't want to have to introduce a newtype for that, especially because it defeats the purpose of (in this specific case) generically deriving a user-friendly type. Groetjes, Martijn.

I agree this is wrong. I've created a Trac bug report http://hackage.haskell.org/trac/ghc/ticket/3714 Thanks for pointing it out Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe- | bounces@haskell.org] On Behalf Of Martijn van Steenbergen | Sent: 27 November 2009 10:35 | To: Haskell Cafe | Subject: [Haskell-cafe] Type synonym family inside type class | | Hello, | | I have a type family and a type class: | | > type family ErrorAlg (f :: (* -> *) -> * -> *) e ix :: * | | > class MkErrorAlg f where | > mkErrorAlg :: ErrorAlg f e a -> f (K0 a) ix -> Either e a | | Instances for these two really go hand in hand, so I thought I would | move the type family into the type class. However, this causes GHC to | complain about the type variables that are bound on the LHS of the type | synonym: | | > Not in scope: type variable `e' | > Not in scope: type variable `ix' | | In function types, using new type variables (i.e. type variables not | bound by the type class header) implicitly means universal | quantification over these variables. Why is this disallowed in type | families inside type classes? | | Thanks, | | Martijn. | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Martijn van Steenbergen
-
Sean Leather
-
Simon Peyton-Jones