TypeCompose 0.5.1 → 0.6.0
raw patch · 11 files changed
+311/−246 lines, 11 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Pair: apPair :: (Applicative h, Pair f) => PairTy (h :. f)
- Data.Pair: arPair :: (Arrow ~>, Unpair f, Pair g) => PairTy (Arrw ~> f g)
- Data.Pair: class Copair f
- Data.Pair: class Pair f
- Data.Pair: class Unpair f
- Data.Pair: cofst :: (Copair f) => f a -> f (a, b)
- Data.Pair: copair :: (Copair f, Monoid_f f) => PairTy f
- Data.Pair: cosnd :: (Copair f) => f b -> f (a, b)
- Data.Pair: instance (Arrow (~>)) => Copair (Flip (~>) o)
- Data.Pair: instance (Arrow (~>), Monoid_f (Flip (~>) o)) => Pair (Flip (~>) o)
- Data.Pair: instance (Arrow (~>), Unpair f, Pair g) => Pair (Arrw (~>) f g)
- Data.Pair: instance (Copair f, Copair g) => Copair (f :*: g)
- Data.Pair: instance (Functor h, Copair f) => Copair (h :. f)
- Data.Pair: instance (Monoid o) => Pair (Const o)
- Data.Pair: instance (Monoid u) => Pair ((,) u)
- Data.Pair: instance (Pair f, Pair g) => Pair (f :*: g)
- Data.Pair: instance Copair (Const e)
- Data.Pair: instance Copair Endo
- Data.Pair: instance Pair ((->) u)
- Data.Pair: instance Pair Endo
- Data.Pair: instance Pair IO
- Data.Pair: instance Pair Id
- Data.Pair: instance Unpair (Const a)
- Data.Pair: instance Unpair Endo
- Data.Pair: instance Unpair Id
- Data.Pair: instance Unpair []
- Data.Pair: pair :: (Pair f) => PairTy f
- Data.Pair: pairEdit :: (Functor m, Monoid (m ((c, d) -> (c, d)))) => (m c, m d) -> m ((c, d) -> (c, d))
- Data.Pair: pairEditM :: (MonadPlus m) => (m c, m d) -> m ((c, d) -> (c, d))
- Data.Pair: pfst :: (Unpair f) => f (a, b) -> f a
- Data.Pair: ppPair :: (Functor g, Pair g, Pair f) => PairTy (g :. f)
- Data.Pair: psnd :: (Unpair f) => f (a, b) -> f b
- Data.Pair: type PairTy f = forall a b. f a -> f b -> f (a, b)
- Data.Pair: type UnpairTy f = forall a b. f (a, b) -> (f a, f b)
- Data.Pair: unpair :: (Unpair f) => UnpairTy f
+ Data.Zip: apZip :: (Applicative h, Zip f) => ZipTy (h :. f)
+ Data.Zip: arZip :: (Arrow ~>, Unzip f, Zip g) => ZipTy (Arrw ~> f g)
+ Data.Zip: class Cozip f
+ Data.Zip: class Unzip f
+ Data.Zip: class Zip f
+ Data.Zip: cofsts :: (Cozip f) => f a -> f (a, b)
+ Data.Zip: cosnds :: (Cozip f) => f b -> f (a, b)
+ Data.Zip: cozip :: (Cozip f, Monoid_f f) => ZipTy f
+ Data.Zip: fsts :: (Unzip f) => f (a, b) -> f a
+ Data.Zip: instance (Arrow (~>)) => Cozip (Flip (~>) o)
+ Data.Zip: instance (Arrow (~>), Monoid_f (Flip (~>) o)) => Zip (Flip (~>) o)
+ Data.Zip: instance (Arrow (~>), Unzip f, Zip g) => Zip (Arrw (~>) f g)
+ Data.Zip: instance (Cozip f, Cozip g) => Cozip (f :*: g)
+ Data.Zip: instance (Functor h, Cozip f) => Cozip (h :. f)
+ Data.Zip: instance (Monoid o) => Zip (Const o)
+ Data.Zip: instance (Monoid u) => Zip ((,) u)
+ Data.Zip: instance (Zip f, Zip g) => Zip (f :*: g)
+ Data.Zip: instance Cozip (Const e)
+ Data.Zip: instance Cozip Endo
+ Data.Zip: instance Unzip ((,) a)
+ Data.Zip: instance Unzip ((->) a)
+ Data.Zip: instance Unzip (Const a)
+ Data.Zip: instance Unzip Endo
+ Data.Zip: instance Unzip Id
+ Data.Zip: instance Unzip []
+ Data.Zip: instance Zip ((->) u)
+ Data.Zip: instance Zip Endo
+ Data.Zip: instance Zip IO
+ Data.Zip: instance Zip Id
+ Data.Zip: instance Zip []
+ Data.Zip: pairEdit :: (Functor m, Monoid (m ((c, d) -> (c, d)))) => (m c, m d) -> m ((c, d) -> (c, d))
+ Data.Zip: pairEditM :: (MonadPlus m) => (m c, m d) -> m ((c, d) -> (c, d))
+ Data.Zip: ppZip :: (Functor g, Zip g, Zip f) => ZipTy (g :. f)
+ Data.Zip: snds :: (Unzip f) => f (a, b) -> f b
+ Data.Zip: type UnzipTy f = forall a b. f (a, b) -> (f a, f b)
+ Data.Zip: type ZipTy f = forall a b. f a -> f b -> f (a, b)
+ Data.Zip: unzip :: (Unzip f) => UnzipTy f
+ Data.Zip: zip :: (Zip f) => ZipTy f
Files
- TypeCompose.cabal +2/−2
- src/Control/Compose.hs +12/−3
- src/Data/Bijection.hs +1/−4
- src/Data/CxMonoid.hs +1/−3
- src/Data/Lambda.hs +1/−3
- src/Data/Pair.hs +0/−220
- src/Data/Partial.hs +6/−5
- src/Data/RefMonad.hs +1/−3
- src/Data/Title.hs +1/−3
- src/Data/Zip.hs +232/−0
- wikipage.tw +54/−0
TypeCompose.cabal view
@@ -1,5 +1,5 @@ Name: TypeCompose-Version: 0.5.1+Version: 0.6.0 Synopsis: Type composition classes & instances Category: Composition, Control Description:@@ -27,7 +27,7 @@ Data.Bijection Data.CxMonoid Data.RefMonad- Data.Pair+ Data.Zip Data.Lambda Data.Title Data.Partial
src/Control/Compose.hs view
@@ -214,11 +214,20 @@ pure = O . pure . pure (<*>) = inO2 (liftA2 (<*>)) +-- Possible Alternative instances: --- Possible Monoid instances+-- instance (Applicative g, Alternative f) => Alternative (g :. f) where+-- empty = O (pure empty)+-- (<|>) = inO2 (liftA2 (<|>)) --- instance (Monoid change, Applicative m, Monoid o)--- => Monoid (SourceG change m o) where+-- instance (Alternative g, Applicative f) => Alternative (g :. f) where+-- empty = O empty+-- (<|>) = inO2 (<|>)+++-- Possible Monoid instances:++-- instance (Applicative g, Applicative f, Monoid a) => Monoid ((g :. f) a) where -- mempty = pure mempty -- mappend = liftA2 mappend
src/Data/Bijection.hs view
@@ -1,8 +1,5 @@ {-# LANGUAGE TypeOperators, CPP #-}--- For ghc 6.6 compatibility--- {-# OPTIONS -fglasgow-exts #-}--+{-# OPTIONS_GHC -Wall #-} ---------------------------------------------------------------------- -- | -- Module : Data.Bijection
src/Data/CxMonoid.hs view
@@ -1,7 +1,5 @@ {-# LANGUAGE TypeSynonymInstances, TypeOperators, GeneralizedNewtypeDeriving #-}--- -- For ghc 6.6 compatibility--- {-# OPTIONS -fglasgow-exts #-}-+{-# OPTIONS_GHC -Wall #-} ---------------------------------------------------------------------- -- | -- Module : Data.CxMonoid
src/Data/Lambda.hs view
@@ -1,8 +1,6 @@ {-# LANGUAGE Rank2Types, TypeOperators, MultiParamTypeClasses , FunctionalDependencies, FlexibleInstances, TypeSynonymInstances #-}--- -- For ghc 6.6 compatibility--- {-# OPTIONS -fglasgow-exts #-}-+{-# OPTIONS_GHC -Wall #-} ---------------------------------------------------------------------- -- | -- Module : Data.Lambda
− src/Data/Pair.hs
@@ -1,220 +0,0 @@-{-# LANGUAGE Rank2Types, TypeOperators, FlexibleInstances, FlexibleContexts- , UndecidableInstances, TypeSynonymInstances #-}---- -- For ghc 6.6 compatibility--- {-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}--------------------------------------------------------------------------- |--- Module : Data.Pair--- Copyright : (c) Conal Elliott 2007--- License : BSD3--- --- Maintainer : conal@conal.net--- Stability : experimental--- Portability : GHC--- --- Pair-related type constructor classes. See "Data.Fun" for similar classes.-------------------------------------------------------------------------module Data.Pair- (- -- * Pairings- PairTy, Pair(..)- , apPair, ppPair, arPair- -- * Unpairings- , UnpairTy, Unpair(..)- -- * Dual unpairings- , Copair(..), copair- -- * Misc- , pairEdit, pairEditM- ) where---import Data.Monoid-import Control.Arrow-import Control.Applicative-import Control.Monad -- for pairEdit--import Control.Compose---{----------------------------------------------------------- Pairings-----------------------------------------------------------}---- | Type of 'pair' method-type PairTy f = forall a b. f a -> f b -> f (a,b)---- | Type constructor class for pair-like things. Generalizes 'zip'.--- Here are some standard instance templates you can fill in. They're not--- defined in the general forms below, because they would lead to a lot of--- overlap.--- --- @--- instance Applicative f => Pair f where--- pair = liftA2 (,)--- instance (Applicative h, Pair f) => Pair (h :. f) where--- pair = apPair--- instance (Functor g, Pair g, Pair f) => Pair (g :. f)--- where pair = ppPair--- instance (Arrow (~>), Unpair f, Pair g) => Pair (Arrw (~>) f g) where--- pair = arPair--- instance (Monoid_f h, Copair h) => Pair h where--- pair = copair--- @--- --- Also, if you have a type constructor that's a 'Functor' and a 'Pair',--- here is a way to define '(<*>)' for 'Applicative':--- --- @--- rf <*> rx = uncurry ($) <$> (rf `pair` rx)--- @--class Pair f where- pair :: PairTy f -- ^ Form a pair-like value (generalizes 'zip')---- Standard instances (Applicative f)-instance Monoid u => Pair ((,) u) where pair = liftA2 (,)-instance Pair ((->) u) where pair = liftA2 (,)-instance Pair IO where pair = liftA2 (,)--instance Monoid o => Pair (Const o) where- pair = inConst2 mappend--instance Pair Id where Id a `pair` Id b = Id (a,b)---- Standard instance, e.g., (~>) = (->)--- This one requires UndecidableInstances. Alternatively, specialize to--- (->) and other arrows as desired.-instance (Arrow (~>), Monoid_f (Flip (~>) o)) =>- Pair (Flip (~>) o) where pair = copair---- | Handy for 'Pair' instances-apPair :: (Applicative h, Pair f) => PairTy (h :. f)-apPair = inO2 (liftA2 pair)---- | Handy for 'Pair' instances-ppPair :: (Functor g, Pair g, Pair f) => PairTy (g :. f)-ppPair = inO2 $ \ gfa gfb -> fmap (uncurry pair) (gfa `pair` gfb)---- | Pairing of 'Arrw' values. /Warning/: definition uses 'arr', so only--- use if your arrow has a working 'arr'.-arPair :: (Arrow (~>), Unpair f, Pair g) => PairTy (Arrw (~>) f g)-arPair = inArrw2 $ \ fga fgb ->- arr unpair >>> fga***fgb >>> arr (uncurry pair)---- Standard instance-instance (Arrow (~>), Unpair f, Pair g) => Pair (Arrw (~>) f g)- where pair = arPair--instance (Pair f, Pair g) => Pair (f :*: g) where- pair = inProd2 (pair ***# pair)---{----------------------------------------------------------- Unpairings-----------------------------------------------------------}---- | Type of 'unpair' method. Generalizes 'unzip'.-type UnpairTy f = forall a b. f (a,b) -> (f a, f b)---- | Dissectable as pairs. Minimal instance definition: either (a)--- 'unpair' /or/ (b) both of 'pfst' /and/ 'psnd'.--- A standard template to substitute any 'Functor' @f.@ But watch out for--- effects!--- --- @--- instance Functor f => Unpair f where {pfst = fmap fst; psnd = fmap snd}--- @-class Unpair f where- unpair :: UnpairTy f -- ^ Deconstruct pair-like value- pfst :: f (a,b) -> f a -- ^ First part of pair-like value- psnd :: f (a,b) -> f b -- ^ Second part of pair-like value-- unpair = pfst &&& psnd- pfst = fst.unpair- psnd = snd.unpair--instance Unpair (Const a) where- unpair (Const a) = (Const a, Const a)--instance Unpair Id where- unpair (Id (a,b)) = (Id a, Id b)---- Standard instance-instance Unpair [] where { pfst = fmap fst; psnd = fmap snd }---{----------------------------------------------------------- Dual unpairings-----------------------------------------------------------}---- | Dual to 'Unpair'.--- Especially handy for contravariant functors ('Cofunctor') . Use this--- template (filling in @f@) :--- --- @--- instance Cofunctor f => Copair f where--- { cofst = cofmap fst ; cosnd = cofmap snd }--- @-class Copair f where- cofst :: f a -> f (a,b) -- ^ Pair-like value from first part- cosnd :: f b -> f (a,b) -- ^ Pair-like value from second part--instance Copair (Const e) where- cofst = inConst id- cosnd = inConst id---- Standard instance for contravariant functors-instance Arrow (~>) => Copair (Flip (~>) o) where- { cofst = cofmap fst ; cosnd = cofmap snd }--instance (Functor h, Copair f) => Copair (h :. f) where- cofst = inO (fmap cofst)- cosnd = inO (fmap cosnd)--instance (Copair f, Copair g) => Copair (f :*: g) where- cofst = inProd (cofst *** cofst)- cosnd = inProd (cosnd *** cosnd)---- | Pairing of 'Copair' values. Combines contribution of each.-copair :: (Copair f, Monoid_f f) => PairTy f-fa `copair` fb = cofst fa `mappend_f` cosnd fb---- Control.Applicative.Endo--- Handy for "partial values" <http://haskell.org/haskellwiki/Partial>--instance Unpair Endo where -- Parital == Endo- pfst = inEndo $ (fst .) . (. (\ a -> (a, undefined)))- psnd = inEndo $ (snd .) . (. (\ b -> (undefined, b)))--instance Copair Endo where -- Parital == Endo- cofst = inEndo first- cosnd = inEndo second---- Standard instance for (Monoid_f h, Copair h)-instance Pair Endo where pair = copair----{----------------------------------------------------------- Misc-----------------------------------------------------------}---- | Turn a pair of sources into a source of pair-editors. See--- <http://conal.net/blog/posts/pairs-sums-and-reactivity/>.--- 'Functor'\/'Monoid' version. See also 'pairEditM'.--pairEdit :: (Functor m, Monoid (m ((c,d) -> (c,d)))) =>- (m c,m d) -> m ((c,d) -> (c,d))-pairEdit (ce,de) =- fmap (first.const) ce `mappend` fmap (second.const) de----- | Turn a pair of sources into a source of pair-editors. See--- <http://conal.net/blog/posts/pairs-sums-and-reactivity/>.--- Monad version. See also 'pairEdit'.-pairEditM :: MonadPlus m => (m c,m d) -> m ((c,d) -> (c,d))-pairEditM (ce,de) =- liftM (first.const) ce `mplus` liftM (second.const) de
src/Data/Partial.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE TypeSynonymInstances #-}-+{-# OPTIONS_GHC -Wall #-} ---------------------------------------------------------------------- -- | -- Module : Data.Partial@@ -28,12 +28,13 @@ -- via 'FunAble' instance ) where +import Prelude hiding (zip,unzip) import Data.Monoid import Control.Arrow import Control.Compose (FunAble(..),inEndo) -import Data.Pair+import Data.Zip -- | Partial value. Represented an endomorphism, which is a 'Monoid' -- under 'id' and '(.)'. Then 'mempty' is the completely undefined value,@@ -98,15 +99,15 @@ -- @PartialFun a@. pFirst :: PartialX a a' -> PartialX (a,b) (a',b)-pFirst f = uncurry pair . first f . unpair+pFirst f = uncurry zip . first f . unzip pSecond :: PartialX b b' -> PartialX (a,b) (a,b')-pSecond g = uncurry pair . second g . unpair+pSecond g = uncurry zip . second g . unzip -- The following is not quite equivalent, since mappend doesn't commute. -- -- pSecond g ab = pUnSnd (g b) `mappend` pUnFst a--- where (a,b) = dsPPair ab+-- where (a,b) = dsPZip ab -- TODO: DeepArrow instance for PartialFun (perhaps in the DeepArrow
src/Data/RefMonad.hs view
@@ -1,7 +1,5 @@ {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}--- -- For ghc 6.6 compatibility--- {-# OPTIONS -fglasgow-exts #-}-+{-# OPTIONS_GHC -Wall #-} ---------------------------------------------------------------------- -- | -- Module : Data.RefMonad
src/Data/Title.hs view
@@ -1,7 +1,5 @@ {-# LANGUAGE FlexibleInstances, OverlappingInstances, TypeOperators, TypeSynonymInstances #-}--- -- For ghc 6.6 compatibility--- {-# OPTIONS -fglasgow-exts -fallow-overlapping-instances #-}-+{-# OPTIONS_GHC -Wall #-} ---------------------------------------------------------------------- -- | -- Module : Data.Title
+ src/Data/Zip.hs view
@@ -0,0 +1,232 @@+{-# LANGUAGE Rank2Types, TypeOperators, UndecidableInstances #-}+{-# OPTIONS_GHC -Wall #-}+----------------------------------------------------------------------+-- |+-- Module : Data.Zip+-- Copyright : (c) Conal Elliott 2007+-- License : BSD3+-- +-- Maintainer : conal@conal.net+-- Stability : experimental+-- Portability : GHC+-- +-- Zip-related type constructor classes.+-- +-- This module is similar to @Control.Functor.Zip@ in the+-- @category-extras@ package, but it does not require a 'Functor'+-- superclass.+-- +-- This module defines generalized 'zip' and 'unzip', so if you use it,+-- you'll have to+--+-- @+-- import Prelude hiding (zip,unzip)+-- @+----------------------------------------------------------------------++module Data.Zip+ (+ -- * Zippings+ ZipTy, Zip(..)+ , apZip, ppZip, arZip+ -- * Unzipings+ , UnzipTy, Unzip(..)+ -- * Dual unzipings+ , Cozip(..), cozip+ -- * Misc+ , pairEdit, pairEditM+ ) where+++import Prelude hiding (zip,unzip)+import qualified Prelude as P++import Data.Monoid+import Control.Arrow+import Control.Applicative+import Control.Monad -- for pairEdit++import Control.Compose+++{----------------------------------------------------------+ Zippings+----------------------------------------------------------}++-- | Type of 'zip' method+type ZipTy f = forall a b. f a -> f b -> f (a,b)++-- | Type constructor class for 'zip'-like things.+-- Here are some standard instance templates you can fill in. They're not+-- 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+-- @+-- +-- 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)+-- @++class Zip f where+ zip :: ZipTy f -- ^ Generalized 'P.zip'++-- Standard instances (Applicative f)+instance Zip [] where zip = P.zip+instance Monoid u => Zip ((,) u) where zip = liftA2 (,)+instance Zip ((->) u) where zip = liftA2 (,)+instance Zip IO where zip = liftA2 (,)++instance Monoid o => Zip (Const o) where+ zip = inConst2 mappend++instance Zip Id where Id a `zip` Id b = Id (a,b)++-- Standard instance, e.g., (~>) = (->)+-- This one requires UndecidableInstances. Alternatively, specialize to+-- (->) and other arrows as desired.+instance (Arrow (~>), Monoid_f (Flip (~>) o)) =>+ Zip (Flip (~>) o) where zip = cozip++-- | Handy for 'Zip' instances+apZip :: (Applicative h, Zip f) => ZipTy (h :. f)+apZip = inO2 (liftA2 zip)++-- | Handy for 'Zip' instances+ppZip :: (Functor g, Zip g, Zip f) => ZipTy (g :. f)+ppZip = inO2 $ \ gfa gfb -> uncurry zip <$> (gfa `zip` gfb)++-- | Ziping of 'Arrw' values. /Warning/: definition uses 'arr', so only+-- use if your arrow has a working 'arr'.+arZip :: (Arrow (~>), Unzip f, Zip g) => ZipTy (Arrw (~>) f g)+arZip = inArrw2 $ \ fga fgb ->+ arr unzip >>> fga***fgb >>> arr (uncurry zip)++-- Standard instance+instance (Arrow (~>), Unzip f, Zip g) => Zip (Arrw (~>) f g)+ where zip = arZip++instance (Zip f, Zip g) => Zip (f :*: g) where+ zip = inProd2 (zip ***# zip)+++{----------------------------------------------------------+ Unzipings+----------------------------------------------------------}++-- | Type of 'unzip' method. Generalizes 'P.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}+-- @+class Unzip f where+ unzip :: UnzipTy f -- ^ generalized unzip+ fsts :: f (a,b) -> f a -- ^ First part of pair-like value+ snds :: f (a,b) -> f b -- ^ Second part of pair-like value++ unzip = fsts &&& snds+ fsts = fst.unzip+ snds = snd.unzip++instance Unzip [] where+ unzip = P.unzip -- single pass. don't use default+ fsts = fmap fst+ snds = fmap snd ++-- Some standard instances for functors+instance Unzip ((->) a) where { fsts = fmap fst; snds = fmap snd }+instance Unzip ((,) a) where { fsts = fmap fst; snds = fmap snd }+instance Unzip (Const a) where { fsts = fmap fst; snds = fmap snd }+instance Unzip Id where { fsts = fmap fst; snds = fmap snd }+++{----------------------------------------------------------+ Dual unzipings+----------------------------------------------------------}++-- | Dual to 'Unzip'.+-- Especially handy for contravariant functors ('Cofunctor') . Use this+-- template (filling in @f@) :+-- +-- @+-- 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++instance Cozip (Const e) where+ cofsts = inConst id+ cosnds = inConst id++-- Standard instance for contravariant functors+instance Arrow (~>) => Cozip (Flip (~>) o) where+ { cofsts = cofmap fst ; cosnds = cofmap snd }++instance (Functor h, Cozip f) => Cozip (h :. f) where+ cofsts = inO (fmap cofsts)+ cosnds = inO (fmap cosnds)++instance (Cozip f, Cozip g) => Cozip (f :*: g) where+ cofsts = inProd (cofsts *** cofsts)+ cosnds = inProd (cosnds *** cosnds)++-- | Ziping of 'Cozip' values. Combines contribution of each.+cozip :: (Cozip f, Monoid_f f) => ZipTy f+fa `cozip` fb = cofsts fa `mappend_f` cosnds fb++-- Control.Applicative.Endo+-- Handy for "partial values" <http://haskell.org/haskellwiki/Partial>++instance Unzip Endo where -- Parital == Endo+ fsts = inEndo $ (fst .) . (. (\ a -> (a, undefined)))+ snds = inEndo $ (snd .) . (. (\ b -> (undefined, b)))++instance Cozip Endo where -- Parital == Endo+ cofsts = inEndo first+ cosnds = inEndo second++-- Standard instance for (Monoid_f h, Cozip h)+instance Zip Endo where zip = cozip++++{----------------------------------------------------------+ Misc+----------------------------------------------------------}++-- | Turn a pair of sources into a source of pair-editors. See+-- <http://conal.net/blog/posts/pairs-sums-and-reactivity/>.+-- 'Functor'\/'Monoid' version. See also 'pairEditM'.++pairEdit :: (Functor m, Monoid (m ((c,d) -> (c,d)))) =>+ (m c,m d) -> m ((c,d) -> (c,d))+pairEdit (ce,de) =+ fmap (first.const) ce `mappend` fmap (second.const) de+++-- | Turn a pair of sources into a source of pair-editors. See+-- <http://conal.net/blog/posts/pairs-sums-and-reactivity/>.+-- Monad version. See also 'pairEdit'.+pairEditM :: MonadPlus m => (m c,m d) -> m ((c,d) -> (c,d))+pairEditM (ce,de) =+ liftM (first.const) ce `mplus` liftM (second.const) de
+ wikipage.tw view
@@ -0,0 +1,54 @@+[[Category:Composition]]+[[Category:Applicative]]+[[Category:Libraries]]+[[Category:Packages]]++== Abstract ==++'''TypeCompose''' provides some classes & instances for forms of type composition, as well as some modules that haven't found another home.++Besides this wiki page, here are more ways to find out about TypeCompose:+* Visit the [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/TypeCompose Hackage page] for library documentation and to download & install.+* Or install with <tt>cabal install TypeCompose</tt>.+* Get the code repository: <tt>darcs get http://code.haskell.org/TypeCompose</tt>.+* See the [[TypeCompose/Versions| version history]].++== Type composition ==++The <hask>Control.Compose</hask> module includes+* Various type compositions (unary/unary, binary/unary, etc). Most are from [http://www.soi.city.ac.uk/~ross/papers/Applicative.html Applicative Programming with Effects]. In particular, <hask>g `O` f</hask> composes functors in to functors and applicative functors (AFs) into AFs. (In contrast, monads do not in general compose.) Composition makes AF-based programming simple and elegant, partly because we don't need an AF counterpart to monad transformers.+* Cofunctors (contravariant functors). Great for "consumer" types, just as functors suit "producer" (container) types. There are several composition options.+* Type argument flip. Handy for cofunctors: use <hask>Flip (->) o</hask>, for <hask>(-> o)</hask>.+* Constructor in pairs: <hask>(f a, g a)</hask>.+* Constructor in arrows/functions: <hask>f a ~> g a</hask>.++== Other features ==++=== Composable bijections ===++Given all the type constructors and compositions of them, I found myself writing some pretty awkward code to wrap & unwrap through multiple layers. Composable bijections help a lot.++The <hask>Data.Bijection</hask> module is inspired by [http://citeseer.ist.psu.edu/alimarine05there.html There and Back Again: Arrows for Invertible Programming], though done here in a less general setting.++=== Pair- & function-like types ===++The <hask>Data.Pair</hask> and <hask>Data.Lambda</hask> patterns emerged while working on [[DeepArrow]] and [[Eros]]. <hask>Data.Pair</hask> generalizes <hask>zip</hask> and <hask>unzip</hask> from <hask>[]</hask> to other functors. It also provides variants of type <hask>f a -> f (a,b)</hask> and <hask>f a -> f (a,b)</hask>. <hask>Data.Lambda</hask> is similar with classes for lambda-like constructions.++For example uses of <hask>Pair</hask> and <hask>Lambda</hask>, see [[TV]] and [[Eros]].++=== References ===++Monads with references. Direct rip-off from [http://citeseer.ist.psu.edu/473734.html Global Variables in Haskell].++=== Titling ===++For giving titles to things. I know it sounds kind of random. More useful than I first thought. Used in [[Phooey]], [[TV]], and [[Eros]].++=== Partial values ===++A monoid of partial values. See the [http://conal.net/blog/posts/a-type-for-partial-values/ teaser] and [http://conal.net/blog/posts/implementing-a-type-for-partial-values/ solution] blog+posts.++=== Context-dependent monoids ===++Bit of an oddball also. <hask>Data.CxMonoid</hask> defines a sort of meta-monoid, that can be supplied dynamically with choices of <hask>mempty</hask> and <hask>mappend</hask>. Used in [[Phooey]] (starting with version 1.3) so that layout could be a monoid but still vary in style.