1 patch for repository http://code.haskell.org/~ross/transformers: Mon Dec 10 22:58:35 EST 2012 blamario@acanac.net * Adding Data.Functor.Coproduct New patches: [Adding Data.Functor.Coproduct blamario@acanac.net**20121211035835 Ignore-this: 7d1d7ca1ed2f0194358a58c02552d5d0 ] { addfile ./Data/Functor/Coproduct.hs hunk ./Data/Functor/Coproduct.hs 1 +----------------------------------------------------------------------------- +-- | +-- Module : Data.Functor.Coproduct +-- Copyright : (C) 2008-2012 Edward Kmett +-- License : BSD-style (see the file LICENSE) +-- +-- Maintainer : Edward Kmett +-- Stability : provisional +-- Portability : portable +---------------------------------------------------------------------------- + +module Data.Functor.Coproduct + ( Coproduct(..) + , left + , right + , coproduct + ) where + +import Data.Foldable (Foldable(foldMap)) +import Data.Traversable (Traversable(traverse)) + +newtype Coproduct f g a = Coproduct { getCoproduct :: Either (f a) (g a) } + +left :: f a -> Coproduct f g a +left = Coproduct . Left + +right :: g a -> Coproduct f g a +right = Coproduct . Right + +coproduct :: (f a -> b) -> (g a -> b) -> Coproduct f g a -> b +coproduct f g = either f g . getCoproduct + +instance (Functor f, Functor g) => Functor (Coproduct f g) where + fmap f = Coproduct . coproduct (Left . fmap f) (Right . fmap f) + +instance (Foldable f, Foldable g) => Foldable (Coproduct f g) where + foldMap f = coproduct (foldMap f) (foldMap f) + +instance (Traversable f, Traversable g) => Traversable (Coproduct f g) where + traverse f = coproduct + (fmap (Coproduct . Left) . traverse f) + (fmap (Coproduct . Right) . traverse f) hunk ./transformers.cabal 70 Control.Monad.Trans.Writer.Strict Data.Functor.Compose Data.Functor.Constant + Data.Functor.Coproduct Data.Functor.Identity Data.Functor.Product Data.Functor.Reverse } Context: [remove accidental leakage Ross Paterson **20121209110500 Ignore-this: 54fe9af5dfc4094daf77e77c38ea42b ] [add missing file Control/Monad/Signatures.hs Ross Paterson **20121207134645 Ignore-this: ce37016ebbefd64f889b42eea476b391 ] [bump minor version (extra names added) Ross Paterson **20120628224825 Ignore-this: d860a4f5ed8ca9bfdd4c6fb39711761e ] [TAG 0.3.0.0 Ross Paterson **20120628224617 Ignore-this: 20616f65c473b16da9d55466a12439e0 ] [turn off orphan warnings for Control.Monad.Trans.Error Ross Paterson **20120628223655 Ignore-this: adab8b88a7b794643b59e3af6e54a3fd ] [avoid shadowing Ross Paterson **20120628222944 Ignore-this: bf4ee18e6179e9b22e2a0eb97d515245 ] [unused variables in patterns Ross Paterson **20120623172747 Ignore-this: edd501b2af6478a7a387e985d960ceac ] [remove superfluous imports Ross Paterson **20120623172554 Ignore-this: 3e91da95c429f53e110e7d1d4b68535 ] [uniform formatting (no functional change) Ross Paterson **20120523091123 Ignore-this: e5239dd0d5eda071706918385c83fe85 ] [expand description Ross Paterson **20120501170213 Ignore-this: d5c142b68e1d871ce9f256ab5e232d9f ] [introduce type synonyms for signatures of complex operations Ross Paterson **20120501081936 Ignore-this: e625f1c300097e85f179b745fd4a9a0e ] [3-layer example Ross Paterson **20120501081557 Ignore-this: 4b5ed9418daa62111b41be13b23ed3ac ] [bump cabal version (uses source-repository) Ross Paterson **20120322155859 Ignore-this: 2c1daaa3e295bde18a19b9776d8964f8 ] [expand definitions of censor, gets, listens and modify to avoid redundant binds Ross Paterson **20120308175633 Ignore-this: 74bee34bb9db891f1f5d7cfa5fd0c149 ] [doc tweaks Ross Paterson **20120308003223 Ignore-this: 7145069d3c2b832c5f517be0bf2b5bec ] [update doc comments Ross Paterson **20120304003400 Ignore-this: 31c6e129c3bce3590ad7ee67e1a9a95d ] [rename Fallback as Lift Ross Paterson **20120218010458 Ignore-this: 95f05fcbc53e406edeb35d9106028107 ] [add source repo location Ross Paterson **20120218010417 Ignore-this: f0620a7d07a7de362d0ae1c5c243150b ] [identify reader and asks Ross Paterson **20120218010319 Ignore-this: a789cd37b7e53a1212117127bfc37250 ] [identify reader and asks Ross Paterson **20120125124847 Ignore-this: f47ab41b46cfb279f31b1306fcdd2481 ] [generalized state, reader and writer constructor functions Ross Paterson **20120125024352 Ignore-this: fbfa38a2fc2e454e9ce9a983fcf74d91 Generalized to the monad transformer, as suggested by Twan van Laarhoven. ] [backwards compatibility Ross Paterson **20120125023147 Ignore-this: d212077bb8322cd53440f56c9775445e ] [fix typo reported by Patrick Palka Ross Paterson **20110813093623] [bump version number Ross Paterson **20110723075517 Ignore-this: 98e6c24071c8f70e0f33cd83cd5271af adding instances for existing types required a new major version ] [add Fallback transformer, a generalization of Errors Ross Paterson **20110723075421 Ignore-this: 35780cc462ed7afee3effb2831e57c76 ] [add Backwards/Reverse suggested by Russell O'Connor Ross Paterson **20110723075326 Ignore-this: 47b6c92edeb7c32dcf0521b7595760dc ] [drop reference to monads-fd Ross Paterson **20110709174857 Ignore-this: 376e0786643160421a573a2d615d436a ] [fix typo reported by Yitzchak Gale Ross Paterson **20110623164929 Ignore-this: 2cfca43dcd73cf4a96bd8b4bf58446f ] [use catchIOError instead of deprecated catch for base > 4.3.1 Ross Paterson **20110524001110 Ignore-this: 6082bdf78077243e32c90b67e3b93059 ] [add MonadFix instance for MaybeT Ross Paterson **20110408135339 Ignore-this: f8dc6ea7e1085c231f65ebd6a53f47a4 suggested by Job Vranish. ] [add MonadFix instance for IdentityT Ross Paterson **20110408135319 Ignore-this: 35a0e7a62299a25d6831c5f16b517b6b ] [trim white space Ross Paterson **20110408135224 Ignore-this: 790fb10f0728521f3e9bdbc164ea234a ] [add Foldable and Traversable instances Ross Paterson **20110408121731 Ignore-this: 1f7ca06d5838c17be2c1c9b4a083ffef Proposed by Edward Kmett on the libraries list in January 2011. ] [add Monad instances for Product Ross Paterson **20110408121533 Ignore-this: 57fbf5c3254f7bd364058f2b7cacc830 Proposed by Edward Kmett on the libraries list, January 2011. ] [TAG 0.2.2.0 Ross Paterson **20110408121025 Ignore-this: 12218f2ddc5417a884bf49c6d51b7264 ] Patch bundle hash: f3dbb123460af33da836a3f4f46a88cdfa57b9b1