Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE DeriveTraversable, ExistentialQuantification #-}
- data Tree a
- = L a -- Leaf holds data
- | N [Tree a] -- Node holds list of trees
- deriving (Functor, Foldable, Traversable, Show)
- aTree :: Tree Int
- aTree
- = N
- [ L 5
- , N
- [ L 42
- , L 41
- ]
- , L 7
- ]
- data Showable = forall a. Show a => Sh a
- instance Show Showable where
- show (Sh a) = show a
- -- deadly want to get rid of `Sh .`-boilerplate
- actions :: [Tree Int -> Showable]
- actions = [Sh . sum, Sh . fmap (+ 1)] -- and many more...
- main :: IO ()
- main = print $ map ($ aTree) actions -- => [95,N [L 6,N [L 43,L 42],L 8]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement