Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. data JoinList m a = Empty
  2. | Single m a
  3. | Append m (JoinList m a) (JoinList m a)
  4. deriving (Eq, Show)
  5.  
  6. tag :: Monoid m => JoinList m a -> m
  7. tag Empty = mempty
  8. tag (Single x _) = x
  9. tag (Append x left right) = x
  10.  
  11. *JoinList Data.Monoid> tag (Append (Product 100) (Single (Product 10) "foo") (Single (Product 10) "bar"))
  12. Product {getProduct = 100}
  13.  
  14. *JoinList Data.Monoid> tag (Empty :: JoinList (Product Integer) String)
  15. Product {getProduct = 1}
  16.  
  17. *JoinList Data.Monoid> tag (Single (Product 5) "foo")
  18. Product {getProduct = 5}
  19.  
  20. tag (Append x left right) = x `mappend` (tag left) `mappend` (tag right)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement