Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# Language
  2.  RankNTypes
  3. ,FunctionalDependencies
  4. ,FlexibleContexts
  5. ,ScopedTypeVariables
  6. #-}
  7.  
  8. module Traversable where
  9.  
  10. import Traversable_r
  11.  
  12. import Data.Monoid (Endo(..))
  13. import Endo1
  14. import Data.Functor.Identity
  15. import Control.Applicative (Const(..))
  16. import Data.Coerce
  17. import Data.Functor.Apply (Apply(..))
  18. import Data.Maybe (fromJust)
  19.  
  20.  
  21.  
  22. ----
  23. -- Functor
  24.  
  25. class Functor_r Identity f => Functor' f
  26. fmap' :: Functor' f => (a -> b) -> f a -> f b
  27. fmap' f = fmap_r (Identity . f . runIdentity)
  28.  
  29. ----
  30. -- Foldable1
  31.  
  32. class Foldable1_r Identity t => Foldable1' t
  33. foldr1' :: Foldable1' t => (Identity a -> Maybe b -> b) -> t a -> b
  34. foldr1' = foldr1_r
  35. foldMap1' :: (Foldable1' t,Semigroup m) => (Identity a -> m) -> t a -> m
  36. foldMap1' = foldMap1_r
  37.  
  38.  
  39. ----
  40. -- Traversable1
  41.  
  42. class Traversable1_r Identity t => Traversable1' t
  43. traverse1' :: (Traversable1' t,Apply f) => (a -> f b) -> t a -> f (t b)
  44. traverse1' f = traverse1_r (fmap Identity . f . runIdentity)
  45.  
  46. ----
  47. -- Foldable
  48.  
  49. class Foldable_r Identity t => Foldable' t
  50. foldMap' :: (Foldable' t,Monoid m) => (a -> m) -> t a -> m
  51. foldMap' f = foldMap_r (f . runIdentity)
  52. foldr' :: Foldable' t => (a -> b -> b) -> b -> t a -> b
  53. foldr' f = foldr_r (f . runIdentity)
  54.  
  55. ----
  56. -- Traversable
  57.  
  58. class Traversable_r Identity t => Traversable' t
  59. traverse' :: (Traversable' t,Applicative f) => (a -> f b) -> t a -> f (t b)
  60. traverse' f = traverse_r (fmap Identity . f . runIdentity)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement