Advertisement
Guest User

Untitled

a guest
May 29th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE   TypeOperators
  2.                ,FlexibleInstances
  3.                ,FlexibleContexts
  4.                ,TypeSynonymInstances
  5.                ,UndecidableInstances
  6.   #-}
  7. {-
  8.                ,MultiParamTypeClasses
  9.                 TypeFamilies
  10. ---}
  11.  
  12. --Showing
  13. import Data.Foldable (Foldable,foldr,toList,foldMap)
  14.  
  15. import Control.Functor.Combinators.Of
  16. import Control.Functor.Combinators.Biff
  17. --import Control.Functor
  18. import Control.Functor.Composition
  19. import Control.Functor.Zip
  20. --import Control.Functor.Fix
  21. --import Control.Functor.Combinators.Lift
  22. --import Control.Functor.Combinators.Const
  23. import Control.Functor
  24. --import Control.Functor.Extras
  25. --import Control.Category.Hask
  26.        
  27. irip :: (Functor f) => Of f (,) a b -> On (,) f a b
  28. irip = mkOn . unfzip . runOf
  29.  
  30. izip :: (Zip f) => On (,) f a b -> Of f (,) a b
  31. izip m = Of $ fzip (fst $ runOn m) (snd $ runOn m)
  32.  
  33. {-
  34. TODO  make a function like this:
  35. f,g,h Functors
  36. f (a,b) => Of [] (,) Int String
  37. f (g (a,b)) => Of ( f `o` g) (,) a b
  38. f (g (h (a,b))) => Of ( f `o` g `o` h) (,) a b
  39. ---}
  40.  
  41. -- Examples of Usage
  42. r = [(1,"hi"),(3,"there"),(4,"you")]
  43. s=[[(1,"hi"),(2,"there"),(3,"you")],[(4,"and"),(5,"again"),(6,"too")]]
  44.  
  45. rr=listTuple
  46. listTuple = Of $ r                  :: Of [] (,) Int String
  47. tupleList = irip listTuple          :: On (,) [] Int String
  48. andBack = izip tupleList            :: Of [] (,) Int String
  49.  
  50. ss=listListTuple
  51. listListTuple=Of $ CompF s          :: Of ([] :.: []) (,) Int String
  52. tupleListList= irip listListTuple   :: On (,) ([] :.: []) Int String
  53. andBackAgain = izip tupleListList   :: Of ([] :.: []) (,) Int String
  54.  
  55.  
  56.  
  57. -- (a->b) -> (c->d) -> (a,c) -> (b,d) bifunctor on (,)
  58. -- :~> without a's (f a -> g a) -> ( CompF k f a -> CompF k g a)
  59.  
  60. --why are these not in category-extras?
  61. instance (Zip f,Zip g,Composition o,Functor (f `o` g)) => Zip ( f `o` g) where
  62.     fzip h j = compose $ fzipWith fzip (decompose h) (decompose j)
  63. --instance (Functor f,Functor g,Composition o) => Functor (f `o` g) where
  64. --    fmap func = compose . (fmap . fmap) func . decompose
  65. --The above conflits with categoty-extras
  66. instance (Foldable f,Foldable g,Composition o) => Foldable ( f `o` g ) where
  67.     foldMap func = (foldMap . foldMap) func . decompose
  68.  
  69. -- For Showing
  70. instance Foldable f => Foldable (Of f (,) a) where
  71.     foldr f x = Data.Foldable.foldr f x
  72.    
  73. instance (Show a, Show (g a),Composition o,Foldable f,Foldable g)
  74.         => Show ( (f `o` g) a) where
  75.     show = show . toList . decompose
  76. instance (Foldable f,Show a,Show b,Show (m a b)) =>Show (Of f m a b) where
  77.     show = show . toList . runOf
  78. instance (Show (f a) , Show (f b) ) => Show (On (,) f a b) where
  79.     show m = "( " ++ show (fst $ runOn m) ++ "   ,   " ++ show (snd $ runOn m) ++ " )"
  80.    
  81.  
  82. ---}
  83. ---}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement