Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE TypeOperators
- ,FlexibleInstances
- ,FlexibleContexts
- ,TypeSynonymInstances
- ,UndecidableInstances
- #-}
- {-
- ,MultiParamTypeClasses
- TypeFamilies
- ---}
- --Showing
- import Data.Foldable (Foldable,foldr,toList,foldMap)
- import Control.Functor.Combinators.Of
- import Control.Functor.Combinators.Biff
- --import Control.Functor
- import Control.Functor.Composition
- import Control.Functor.Zip
- --import Control.Functor.Fix
- --import Control.Functor.Combinators.Lift
- --import Control.Functor.Combinators.Const
- import Control.Functor
- --import Control.Functor.Extras
- --import Control.Category.Hask
- irip :: (Functor f) => Of f (,) a b -> On (,) f a b
- irip = mkOn . unfzip . runOf
- izip :: (Zip f) => On (,) f a b -> Of f (,) a b
- izip m = Of $ fzip (fst $ runOn m) (snd $ runOn m)
- {-
- TODO make a function like this:
- f,g,h Functors
- f (a,b) => Of [] (,) Int String
- f (g (a,b)) => Of ( f `o` g) (,) a b
- f (g (h (a,b))) => Of ( f `o` g `o` h) (,) a b
- ---}
- -- Examples of Usage
- r = [(1,"hi"),(3,"there"),(4,"you")]
- s=[[(1,"hi"),(2,"there"),(3,"you")],[(4,"and"),(5,"again"),(6,"too")]]
- rr=listTuple
- listTuple = Of $ r :: Of [] (,) Int String
- tupleList = irip listTuple :: On (,) [] Int String
- andBack = izip tupleList :: Of [] (,) Int String
- ss=listListTuple
- listListTuple=Of $ CompF s :: Of ([] :.: []) (,) Int String
- tupleListList= irip listListTuple :: On (,) ([] :.: []) Int String
- andBackAgain = izip tupleListList :: Of ([] :.: []) (,) Int String
- -- (a->b) -> (c->d) -> (a,c) -> (b,d) bifunctor on (,)
- -- :~> without a's (f a -> g a) -> ( CompF k f a -> CompF k g a)
- --why are these not in category-extras?
- instance (Zip f,Zip g,Composition o,Functor (f `o` g)) => Zip ( f `o` g) where
- fzip h j = compose $ fzipWith fzip (decompose h) (decompose j)
- --instance (Functor f,Functor g,Composition o) => Functor (f `o` g) where
- -- fmap func = compose . (fmap . fmap) func . decompose
- --The above conflits with categoty-extras
- instance (Foldable f,Foldable g,Composition o) => Foldable ( f `o` g ) where
- foldMap func = (foldMap . foldMap) func . decompose
- -- For Showing
- instance Foldable f => Foldable (Of f (,) a) where
- foldr f x = Data.Foldable.foldr f x
- instance (Show a, Show (g a),Composition o,Foldable f,Foldable g)
- => Show ( (f `o` g) a) where
- show = show . toList . decompose
- instance (Foldable f,Show a,Show b,Show (m a b)) =>Show (Of f m a b) where
- show = show . toList . runOf
- instance (Show (f a) , Show (f b) ) => Show (On (,) f a b) where
- show m = "( " ++ show (fst $ runOn m) ++ " , " ++ show (snd $ runOn m) ++ " )"
- ---}
- ---}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement