Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. {-# Language MultiParamTypeClasses , FunctionalDependencies , DefaultSignatures #-}
  2.  
  3. module Unfoldable where
  4. import Unfoldable_r
  5. import State
  6.  
  7. ----
  8. -- Unfold for Stream
  9.  
  10. class Unfoldable0 f where
  11. unfoldr0 :: s -> State0 s a -> f a
  12. default unfoldr0 :: Unfoldable1 f => s -> State0 s a -> f a
  13. unfoldr0 s f = unfoldr1 s (fmap Just . f)
  14.  
  15. ----
  16. -- Unfold for Linear
  17.  
  18. class Unfoldable0 f => Unfoldable1 f where
  19. unfoldr1 :: s -> State1 s a -> f a
  20. default unfoldr1 :: Unfoldable f => s -> State1 s a -> f a
  21. unfoldr1 s f = unfoldr s (sequence . f)
  22.  
  23. ----
  24. -- Unfold for Stack
  25.  
  26. class Unfoldable1 f => Unfoldable f where
  27. unfoldr :: s -> State s a -> f a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement