Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. data Tree a = Fork a (Forest a) deriving Show
  2. data Forest a = Null | Grows (Tree a) (Forest a) deriving Show
  3.  
  4. foldt :: (a -> f -> t, f, t -> f -> f) -> Tree a -> t
  5. foldt (g,c,h) (Fork x xs) = g x (foldf (g,c,h) xs)
  6.  
  7. foldf :: (a -> f -> t, f, t -> f -> f) -> Forest a -> f
  8. foldf (g,c,h) Null = c
  9. foldf (g,c,h) (Grows x xs) = h (foldt (g,c,h) x) (foldf (g,c,h) xs)
  10.  
  11. unfoldt :: (x -> (a, (x', y)), y -> Maybe ((x, y'), (x', y))) -> (x, y') -> Tree a
  12. unfoldt (phi, psi) (x, y) = case phi x of
  13. (a, y') -> Fork a (unfoldf (phi, psi) y')
  14.  
  15. unfoldf :: (x -> (a, (x', y)), y -> Maybe ((x, y'), (x', y))) -> (x', y) -> Forest a
  16. unfoldf (phi, psi) (x, y) = case psi y of
  17. Nothing -> Null
  18. Just (x', y') -> Grows (unfoldt (phi, psi) x') (unfoldf (phi, psi) y')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement