monad-products (empty) → 0.2.0
raw patch · 4 files changed
+123/−0 lines, 4 filesdep +basedep +semigroupoidssetup-changed
Dependencies added: base, semigroupoids
Files
- Control/Monad/Product.hs +58/−0
- LICENSE +30/−0
- Setup.lhs +7/−0
- monad-products.cabal +28/−0
+ Control/Monad/Product.hs view
@@ -0,0 +1,58 @@+-----------------------------------------------------------------------------+-- |+-- Module : Control.Monad.Product+-- Copyright : (C) 2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+-- Monad Products +----------------------------------------------------------------------------++module Control.Monad.Product+ ( Product(..)+ ) where++import Control.Applicative+import Data.Functor.Bind+import Data.Functor.Alt+import Control.Monad++-- | disjoint 'Graph' union as a 'Monad' product+newtype Product g h a = Product { runProduct :: (g a, h a) } ++instance (Functor g, Functor h) => Functor (Product g h) where+ fmap f (Product (g, h)) = Product (fmap f g, fmap f h)+ b <$ Product (g, h) = Product (b <$ g, b <$ h)++instance (Apply g, Apply h) => Apply (Product g h) where+ Product (gf, hf) <.> Product (ga, ha) = Product (gf <.> ga, hf <.> ha)+ Product (gf, hf) <. Product (ga, ha) = Product (gf <. ga, hf <. ha)+ Product (gf, hf) .> Product (ga, ha) = Product (gf .> ga, hf .> ha)++instance (Applicative g, Applicative h) => Applicative (Product g h) where+ pure a = Product (pure a, pure a)+ Product (gf, hf) <*> Product (ga, ha) = Product (gf <*> ga, hf <*> ha)+ Product (gf, hf) <* Product (ga, ha) = Product (gf <* ga, hf <* ha)+ Product (gf, hf) *> Product (ga, ha) = Product (gf *> ga, hf *> ha)++instance (Bind g, Bind h) => Bind (Product g h) where+ Product (g, h) >>- k = Product (g >>- fst . runProduct . k, h >>- snd . runProduct . k)+ +instance (Monad g, Monad h) => Monad (Product g h) where+ return a = Product (return a, return a)+ Product (g, h) >>= k = Product (g >>= fst . runProduct . k, h >>= snd . runProduct . k)+ Product (ga, ha) >> Product (gb, hb) = Product (ga >> gb, ha >> hb)++instance (Alt g, Alt h) => Alt (Product g h) where+ Product (ga, ha) <!> Product (gb, hb) = Product (ga <!> gb, ha <!> hb)++instance (Alternative g, Alternative h) => Alternative (Product g h) where+ empty = Product (empty, empty)+ Product (ga, ha) <|> Product (gb, hb) = Product (ga <|> gb, ha <|> hb)++instance (MonadPlus g, MonadPlus h) => MonadPlus (Product g h) where+ mzero = Product (mzero, mzero)+ Product (ga, ha) `mplus` Product (gb, hb) = Product (ga `mplus` gb, ha `mplus` hb)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright 2011 Edward Kmett++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.++3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this software+ without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/runhaskell+> module Main (main) where++> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ monad-products.cabal view
@@ -0,0 +1,28 @@+name: monad-products+category: Control, Monads+version: 0.2.0+license: BSD3+cabal-version: >= 1.6+license-file: LICENSE+author: Edward A. Kmett+maintainer: Edward A. Kmett <ekmett@gmail.com>+stability: provisional+homepage: http://github.com/ekmett/monad-products+copyright: Copyright (C) 2011 Edward A. Kmett+synopsis: Haskell 98 monad products+description: Haskell 98 monad products+build-type: Simple++source-repository head+ type: git+ location: git://github.com/ekmett/monad-products.git++library+ build-depends: + base >= 4 && < 4.4,+ semigroupoids >= 1.2.1 && < 1.3.0++ exposed-modules:+ Control.Monad.Product++ ghc-options: -Wall