Skip to content

Instantly share code, notes, and snippets.

@kazu-yamamoto
Created January 6, 2014 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu-yamamoto/8281920 to your computer and use it in GitHub Desktop.
Save kazu-yamamoto/8281920 to your computer and use it in GitHub Desktop.
SYB
{-# LANGUAGE DeriveDataTypeable #-}
module A where
import Data.Typeable (Typeable)
import Data.Generics (everywhere, mkT, Data)
data T = Tree [U] deriving (Show,Data,Typeable)
data U = I Int | T T deriving (Show,Data,Typeable)
plus1 :: U -> U
plus1 (I n) = I (n + 1)
plus1 x = x
tree :: T
tree = Tree [I 1, T (Tree [I 2])]
tree2 :: T
tree2 = everywhere (mkT plus1) tree
{-
> tree2
Tree [I 2,T (Tree [I 3])]
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment