| 1 | {-# OPTIONS -XTypeFamilies -XFunctionalDependencies -XFlexibleInstances #-} |
|---|
| 2 | |
|---|
| 3 | module Bug where |
|---|
| 4 | |
|---|
| 5 | liftM :: (Monad m) => (a -> b) -> (m a -> m b) |
|---|
| 6 | liftM f a = do |
|---|
| 7 | x <- a |
|---|
| 8 | return $ f x |
|---|
| 9 | |
|---|
| 10 | class Tuple t s | s -> t, t -> s where |
|---|
| 11 | tuple :: s -> t |
|---|
| 12 | untuple :: t -> s |
|---|
| 13 | |
|---|
| 14 | instance Tuple (a,b,c,d,e,f,g,h,i) (a,(b,(c,(d,(e,(f,(g,(h,(i,()))))))))) where |
|---|
| 15 | tuple (a,(b,(c,(d,(e,(f,(g,(h,(i,()))))))))) = (a,b,c,d,e,f,g,h,i) |
|---|
| 16 | untuple (a,b,c,d,e,f,g,h,i) = (a,(b,(c,(d,(e,(f,(g,(h,(i,()))))))))) |
|---|
| 17 | |
|---|
| 18 | instance Tuple (a,b,c,d,e,f,g,h,i,j) (a,(b,(c,(d,(e,(f,(g,(h,(i,(j,())))))))))) where |
|---|
| 19 | tuple (a,(b,(c,(d,(e,(f,(g,(h,(i,(j,())))))))))) = (a,b,c,d,e,f,g,h,i,j) |
|---|
| 20 | untuple (a,b,c,d,e,f,g,h,i,j) = (a,(b,(c,(d,(e,(f,(g,(h,(i,(j,())))))))))) |
|---|
| 21 | |
|---|
| 22 | type family Subst x y a |
|---|
| 23 | type instance Subst x y () = () |
|---|
| 24 | type instance Subst x y (a,b) = (Subst x y a, Subst x y b) |
|---|
| 25 | type instance Subst x y (a,b,c,d,e,f,g,h,i) = (Subst x y a, Subst x y b, Subst x y c, Subst x y d, Subst x y e, Subst x y f, Subst x y g, Subst x y h, Subst x y i) |
|---|
| 26 | type instance Subst x y (a,b,c,d,e,f,g,h,i,j) = (Subst x y a, Subst x y b, Subst x y c, Subst x y d, Subst x y e, Subst x y f, Subst x y g, Subst x y h, Subst x y i, Subst x y j) |
|---|
| 27 | |
|---|
| 28 | class (t ~ Subst Int Int t) => Mydata t where |
|---|
| 29 | mymap :: (Monad m) => t -> (d -> m d') -> (c -> m c') -> Subst d c t -> m (Subst d' c' t) |
|---|
| 30 | |
|---|
| 31 | instance Mydata () where |
|---|
| 32 | mymap s f g () = return () |
|---|
| 33 | |
|---|
| 34 | instance (Mydata a, Mydata b) => Mydata (a,b) where |
|---|
| 35 | mymap ~(a,b) f g (x,y) = do |
|---|
| 36 | x' <- mymap a f g x |
|---|
| 37 | y' <- mymap b f g y |
|---|
| 38 | return (x', y') |
|---|
| 39 | |
|---|
| 40 | instance (Mydata a, Mydata b, Mydata c, Mydata d, Mydata e, Mydata f, Mydata g, Mydata h, Mydata i) => Mydata (a,b,c,d,e,f,g,h,i) where |
|---|
| 41 | mymap s f g xs = liftM tuple $ mymap (untuple s) f g (untuple xs) |
|---|
| 42 | |
|---|
| 43 | instance (Mydata a, Mydata b, Mydata c, Mydata d, Mydata e, Mydata f, Mydata g, Mydata h, Mydata i, Mydata j) => Mydata (a,b,c,d,e,f,g,h,i,j) where |
|---|
| 44 | mymap s f g xs = liftM tuple $ mymap (untuple s) f g (untuple xs) |
|---|