```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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 ``` ```{-# LANGUAGE DeriveDataTypeable, RankNTypes#-} {-# OPTIONS -Wall #-} import Data.Data import Data.Maybe(maybeToList) import Data.Generics.Schemes data ABC = ABC Int Double String deriving (Eq, Show, Data, Typeable) data A = A String | Abc B C deriving (Eq, Show, Data, Typeable) data B = B Double | Bca C A deriving (Eq, Show, Data, Typeable) data C = C Int | Cab A B deriving (Eq, Show, Data, Typeable) abc1 :: ABC abc1 = ABC 2012 1.1 "Tatsu" a1 :: A a1 = Abc (Bca (Cab (A "Happy") (B 4.2)) (Abc (B 5.6) (C 512))) (Cab (Abc (B 8.4) (C 208)) (Bca (C 2012) (A "New Year!"))) recMapQ' :: forall a a1 a2. (Data a1, Data a2) => (a1->a) -> a2 -> [a] recMapQ' f x = (maybeToList \$ fmap f (cast x)) ++ concat (gmapQ (recMapQ' f) x) recMapQ :: forall a a1 a2. (Data a1, Data a2) => (a1->a) -> a2 -> [a] recMapQ f x = case fmap f (cast x) of Just y -> [y] Nothing -> concat (gmapQ (recMapQ f) x) recMapT :: forall a b. (Data a, Data b) => (b -> b) -> a -> a recMapT f x = let y = gmapT (recMapT f) x in case (>>= cast) \$ fmap f \$ cast x of Just z -> z Nothing -> y caster :: (Typeable a) => (a -> a) -> (forall b. Typeable b => b -> b) caster f x = case (cast =<<) \$ fmap f \$ cast x of Just y -> y Nothing -> x main :: IO () main = do print a1 print \$ gsize a1 print \$ recMapQ ("Very " ++) a1 print \$ recMapT ("Very " ++) a1 -- print \$ everywhere (caster \$ ("Very " ++)) a1 -- print \$ everywhere'(caster \$ ("Very " ++)) a1 ```
 ```1 2 ``` ```Error occurred ERROR "t.hs" - Can't find imported module "Data.Generics.Schemes" ```