TypeCompose 0.6.2 → 0.6.3
raw patch · 3 files changed
+70/−66 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Zip: zipWith :: (Functor f, Zip f) => (a -> b -> c) -> (f a -> f b -> f c)
+ Data.Zip: zipWith3 :: (Functor f, Zip f) => (a -> b -> c -> d) -> (f a -> f b -> f c -> f d)
Files
- TypeCompose.cabal +1/−1
- src/Control/Compose.hs +20/−34
- src/Data/Zip.hs +49/−31
TypeCompose.cabal view
@@ -1,5 +1,5 @@ Name: TypeCompose-Version: 0.6.2+Version: 0.6.3 Synopsis: Type composition classes & instances Category: Composition, Control Description:
src/Control/Compose.hs view
@@ -122,36 +122,28 @@ There are (at least) two useful 'Monoid' instances, so you'll have to pick one and type-specialize it (filling in all or parts of @g@ and\/or @f@). -@- -- standard Monoid instance for Applicative applied to Monoid- instance (Applicative (g :. f), Monoid a) => Monoid ((g :. f) a) where- { mempty = pure mempty; mappend = liftA2 mappend }- -- Especially handy when g is a Monoid_f.- instance Monoid (g (f a)) => Monoid ((g :. f) a) where- { mempty = O mempty; mappend = inO2 mappend }-@+> -- standard Monoid instance for Applicative applied to Monoid+> instance (Applicative (g :. f), Monoid a) => Monoid ((g :. f) a) where+> { mempty = pure mempty; mappend = liftA2 mappend }+> -- Especially handy when g is a Monoid_f.+> instance Monoid (g (f a)) => Monoid ((g :. f) a) where+> { mempty = O mempty; mappend = inO2 mappend } Corresponding to the first and second definitions above, -@- instance (Applicative g, Monoid_f f) => Monoid_f (g :. f) where- { mempty_f = O (pure mempty_f); mappend_f = inO2 (liftA2 mappend_f) }- instance Monoid_f g => Monoid_f (g :. f) where- { mempty_f = O mempty_f; mappend_f = inO2 mappend_f }-@+> instance (Applicative g, Monoid_f f) => Monoid_f (g :. f) where+> { mempty_f = O (pure mempty_f); mappend_f = inO2 (liftA2 mappend_f) }+> instance Monoid_f g => Monoid_f (g :. f) where+> { mempty_f = O mempty_f; mappend_f = inO2 mappend_f } Similarly, there are two useful 'Functor' instances and two useful 'Cofunctor' instances. -@- instance ( Functor g, Functor f) => Functor (g :. f) where fmap = fmapFF- instance (Cofunctor g, Cofunctor f) => Functor (g :. f) where fmap = fmapCC-@--@- instance (Functor g, Cofunctor f) => Cofunctor (g :. f) where cofmap = cofmapFC- instance (Cofunctor g, Functor f) => Cofunctor (g :. f) where cofmap = cofmapCF-@+> instance ( Functor g, Functor f) => Functor (g :. f) where fmap = fmapFF+> instance (Cofunctor g, Cofunctor f) => Functor (g :. f) where fmap = fmapCC+> +> instance (Functor g, Cofunctor f) => Cofunctor (g :. f) where cofmap = cofmapFC+> instance (Cofunctor g, Functor f) => Cofunctor (g :. f) where cofmap = cofmapCF However, it's such a bother to define the Functor instances per composition type, I've left the fmapFF case in. If you want the fmapCC@@ -356,9 +348,7 @@ -- See also "Arrows and Computation", which notes that the following type -- is "almost an arrow" (<http://www.soi.city.ac.uk/~ross/papers/fop.html>). -- --- @--- newtype ListMap i o = LM ([i] -> [o])--- @+-- > newtype ListMap i o = LM ([i] -> [o]) -- -- http://www.cse.unsw.edu.au/~dons/haskell-1990-2006/msg16550.html @@ -447,9 +437,7 @@ -- (<http://flint.cs.yale.edu/trifonov/papers/sqcc.pdf>) -- Instantiate this schema wherever necessary: ----- @--- instance Monoid_f f where { mempty_f = mempty ; mappend_f = mappend }--- @+-- > instance Monoid_f f where { mempty_f = mempty ; mappend_f = mappend } class Monoid_f m where mempty_f :: forall a. m a mappend_f :: forall a. m a -> m a -> m a@@ -513,11 +501,9 @@ -- other instances, like @[a]@. Here's a template for @App@-free -- instances. -- --- @--- instance (Applicative f, Monoid a) => Monoid (f a) where--- mempty = pure mempty--- mappend = liftA2 mappend--- @+-- > instance (Applicative f, Monoid a) => Monoid (f a) where+-- > mempty = pure mempty+-- > mappend = liftA2 mappend newtype f :$ a = App { unApp :: f a } -- | Compatibility synonym for (:$).
src/Data/Zip.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE Rank2Types, TypeOperators, UndecidableInstances #-}-{-# OPTIONS_GHC -Wall #-}+{-# OPTIONS_GHC -Wall -fenable-rewrite-rules #-} ---------------------------------------------------------------------- -- | -- Module : Data.Zip@@ -20,14 +20,14 @@ -- you'll have to -- -- @--- import Prelude hiding (zip,unzip)+-- import Prelude hiding (zip,zipWith,zipWith3,unzip) -- @ ---------------------------------------------------------------------- module Data.Zip ( -- * Zippings- ZipTy, Zip(..)+ ZipTy, Zip(..), zipWith, zipWith3 , apZip, ppZip, arZip -- * Unzipings , UnzipTy, Unzip(..)@@ -38,8 +38,8 @@ ) where -import Prelude hiding (zip,unzip)-import qualified Prelude as P+import Prelude hiding (zip,zipWith,zipWith3,unzip)+import qualified Prelude import Data.Monoid import Control.Arrow@@ -61,31 +61,50 @@ -- defined in the general forms below, because they would lead to a lot of -- overlap. -- --- @--- instance Applicative f => Zip f where--- zip = liftA2 (,)--- instance (Applicative h, Zip f) => Zip (h :. f) where--- zip = apZip--- instance (Functor g, Zip g, Zip f) => Zip (g :. f)--- where zip = ppZip--- instance (Arrow (~>), Unzip f, Zip g) => Zip (Arrw (~>) f g) where--- zip = arZip--- instance (Monoid_f h, Cozip h) => Zip h where--- zip = cozip--- @+-- > instance Applicative f => Zip f where+-- > zip = liftA2 (,)+-- > instance (Applicative h, Zip f) => Zip (h :. f) where+-- > zip = apZip+-- > instance (Functor g, Zip g, Zip f) => Zip (g :. f)+-- > where zip = ppZip+-- > instance (Arrow (~>), Unzip f, Zip g) => Zip (Arrw (~>) f g) where+-- > zip = arZip+-- > instance (Monoid_f h, Cozip h) => Zip h where+-- > zip = cozip -- -- Also, if you have a type constructor that's a 'Functor' and a 'Zip', -- here is a way to define '(<*>)' for 'Applicative': -- --- @--- rf <*> rx = uncurry ($) <$> (rf `zip` rx)--- @+-- > (<*>) = zipWith ($)+-- +-- Minimum definitions for instances. class Zip f where- zip :: ZipTy f -- ^ Generalized 'P.zip'+ zip :: ZipTy f -- ^ Generalized 'Prelude.zip' +-- Oh yeah! I don't want Zip to assume Functor. See+-- <http://conal.net/blog/posts/more-beautiful-fold-zipping/>.++-- | Generalized 'Prelude.zipWith'+zipWith :: (Functor f, Zip f) =>+ (a -> b -> c)+ -> (f a -> f b -> f c)+zipWith h = (fmap.fmap.fmap) (uncurry h) zip++-- | Generalized 'Prelude.zipWith'+zipWith3 :: (Functor f, Zip f) =>+ (a -> b -> c -> d)+ -> (f a -> f b -> f c -> f d)+zipWith3 h as bs cs = zipWith (uncurry h) (as `zip` bs) cs+++{-# RULES+"zipWith prelude" zipWith = Prelude.zipWith+"zipWith3 prelude" zipWith3 = Prelude.zipWith3+ #-}+ -- Standard instances (Applicative f)-instance Zip [] where zip = P.zip+instance Zip [] where zip = Prelude.zip instance Monoid u => Zip ((,) u) where zip = liftA2 (,) instance Zip ((->) u) where zip = liftA2 (,) instance Zip IO where zip = liftA2 (,)@@ -127,16 +146,15 @@ Unzipings ----------------------------------------------------------} --- | Type of 'unzip' method. Generalizes 'P.unzip'.+-- | Type of 'unzip' method. Generalizes 'Prelude.unzip'. type UnzipTy f = forall a b. f (a,b) -> (f a, f b) -- | Unzippable. Minimal instance definition: either (a) 'unzip' /or/ (b) -- both of 'fsts' /and/ 'snds'. A standard template to substitute any -- 'Functor' @f.@ But watch out for effects! -- --- @--- instance Functor f => Unzip f where {fsts = fmap fst; snds = fmap snd}--- @+-- > instance Functor f => Unzip f where {fsts = fmap fst; snds = fmap snd}+ class Unzip f where unzip :: UnzipTy f -- ^ generalized unzip fsts :: f (a,b) -> f a -- ^ First part of pair-like value@@ -147,7 +165,7 @@ snds = snd.unzip instance Unzip [] where- unzip = P.unzip -- single pass. don't use default+ unzip = Prelude.unzip -- single pass. don't use default fsts = fmap fst snds = fmap snd @@ -166,10 +184,10 @@ -- Especially handy for contravariant functors ('Cofunctor') . Use this -- template (filling in @f@) : -- --- @--- instance Cofunctor f => Cozip f where--- { cofsts = cofmap fst ; cosnds = cofmap snd }--- @+-- +-- > instance Cofunctor f => Cozip f where+-- > { cofsts = cofmap fst ; cosnds = cofmap snd }+ class Cozip f where cofsts :: f a -> f (a,b) -- ^ Zip-like value from first part cosnds :: f b -> f (a,b) -- ^ Zip-like value from second part