1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE FlexibleInstances #-} data N data R newtype List t a = List { unList :: [a] } class Reverse a t u | t -> u, u -> t where rev :: List t a -> List u a instance Reverse a N R where rev = reverse' instance Reverse a R N where rev = reverse' reverse' :: List t a -> List u a reverse' = List . reverse . unList id' :: List t a -> List t a id' = List . id . unList xs :: List N Int xs = List [1..10] {- So now we see the type toggle. *Main> :t xs xs :: List N Int *Main> :t rev xs rev xs :: List R Int *Main> :t rev (rev xs) rev (rev xs) :: List N Int -} |