[Haskell-cafe] Type family fun
Alexander Dunlap
alexander.dunlap at gmail.com
Sat Aug 23 14:46:50 EDT 2008
On Sat, Aug 23, 2008 at 7:55 AM, Chris Eidhof <chris at eidhof.nl> wrote:
> Hey all,
>
> I was playing around with type families, and I have a strange problem.
>
> Suppose we have an alternative to an Either datatype:
>
>> data (:|:) a b = Inl a | Inr b
>
> and a class Ix:
>
>> class Ix i where
>> type IxMap i :: * -> *
>> empty :: IxMap i [Int]
>
> Now I want to give an instance for (a :|: b):
>
>> instance (Ix l, Ix r) => Ix (l :|: r) where
>> type IxMap (l :|: r) = BiApp (IxMap l) (IxMap r)
>> empty = BiApp empty empty
>
> BiApp is defined as following:
>
>> data BiApp a b c = BiApp (a c) (b c)
>
> However, it looks like the recursive calls to empty can't be unified, I get
> the following error message:
>
> Couldn't match expected type `IxMap l'
> against inferred type `IxMap i'
> Expected type: IxMap (l :|: r) [Int]
> Inferred type: BiApp (IxMap i) (IxMap i1) [Int]
> In the expression: BiApp empty empty
> In the definition of `empty': empty = BiApp empty empty
>
> In the inferred type, there should be IxMap l instead of IxMap i, does
> anybody know what I'm doing wrong?
>
> Thanks,
>
> -chris
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
Hi,
I'm not very familiar with type families, but shouldn't BiApp be defined as
> data BiApp a b c = BiApp (a b) (a c)
since you're applying it as BiApp (IxMap l) (IxMap r)?
Alex
More information about the Haskell-Cafe
mailing list