
Am Freitag 22 Januar 2010 17:08:15 schrieb Andrew U. Frank:
i encounter often a problem when i have a class with some operations (say class X with push) applied to a type A b. I then wrap A in a type A_sup, with some more type parameters and i cannot write a instance of class A_sup because i have a kind mismatch. any suggestions? (reordering of the type parameters of A_sup is not a solution, because another class operates on this parameter)
here a simplistic case (i know that A could be reduced to [], my real cases are more complicated).
data A b = A b [b]
data Asup x ab y = Asup x ab y
That doesn't match its use below, perhaps data Asup x ab y = Asup x (A ab) y (matches better with A_2) or use Asup Char (A Int) Float below?
class X a b where push :: b -> a b -> a b
How about type families? class Y a where type Pushy a :: * push :: Pushy a -> a -> a instance Y (A Int) where type Pushy (A Int) = Int push b' (A b bs) = A b' (b:bs) instance Y (Asup Char (A Int) Float) where type Pushy (Asup Char (A Int) Float) = Int push b' (Asup a b c) = Asup a (push b' b) c
instance X A Int where push b' (A b bs) = A b' (b:bs)
instance X Asup Char Int Float where push b' (Asup a b c) = Asup a (push b' b) c
Missing instance X Int Int, but Int has wrong kind for that :)
-- this does not compile because the number of type arguments for X is wrong.
if i try with a type
type A_2 b = Asup Char (A b) Float
instance X A_2 Int where push b' (Asup a b c) = Asup a (push b' b) c
(and --TypeSynonymInstances) i get:
Type synonym `A_2' should have 1 argument, but has been given 0 In the instance declaration for `X A_2 Int'
what is the solution? thank you! andrew