profunctors (empty) → 0.1
raw patch · 4 files changed
+142/−0 lines, 4 filesdep +basedep +comonaddep +semigroupoidssetup-changed
Dependencies added: base, comonad, semigroupoids
Files
- Data/Profunctor.hs +76/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- profunctors.cabal +34/−0
+ Data/Profunctor.hs view
@@ -0,0 +1,76 @@+module Data.Profunctor + ( Profunctor(..)+ , UpStar(..)+ , DownStar(..)+ , WrappedArrow(..)+ ) where++import Control.Arrow+import Control.Category+import Control.Comonad (Cokleisli(..))+import Control.Monad (liftM)+import Prelude hiding (id,(.))++class Profunctor h where+ lmap :: (a -> b) -> h b c -> h a c+ rmap :: (b -> c) -> h a b -> h a c++instance Profunctor (->) where+ lmap = flip (.)+ rmap = (.)++newtype UpStar f d c = UpStar (d -> f c)+instance Functor f => Profunctor (UpStar f) where+ lmap k (UpStar f) = UpStar (f . k)+ rmap k (UpStar f) = UpStar (fmap k . f)++instance Functor f => Functor (UpStar f a) where+ fmap = rmap ++newtype DownStar f d c = DownStar (f d -> c)+instance Functor f => Profunctor (DownStar f) where+ lmap k (DownStar f) = DownStar (f . fmap k)+ rmap k (DownStar f) = DownStar (k . f)++instance Functor (DownStar f a) where+ fmap k (DownStar f) = DownStar (k . f)++newtype WrappedArrow k a b = WrapArrow { unwrapArrow :: k a b } ++instance Category k => Category (WrappedArrow k) where+ WrapArrow f . WrapArrow g = WrapArrow (f . g)+ id = WrapArrow id++instance Arrow k => Arrow (WrappedArrow k) where+ arr = WrapArrow . arr+ first = WrapArrow . first . unwrapArrow+ second = WrapArrow . second . unwrapArrow + WrapArrow a *** WrapArrow b = WrapArrow (a *** b)+ WrapArrow a &&& WrapArrow b = WrapArrow (a &&& b)+ +instance ArrowZero k => ArrowZero (WrappedArrow k) where+ zeroArrow = WrapArrow zeroArrow++instance ArrowChoice k => ArrowChoice (WrappedArrow k) where+ left = WrapArrow . left . unwrapArrow+ right = WrapArrow . right . unwrapArrow+ WrapArrow a +++ WrapArrow b = WrapArrow (a +++ b)+ WrapArrow a ||| WrapArrow b = WrapArrow (a ||| b)+ +instance ArrowApply k => ArrowApply (WrappedArrow k) where+ app = WrapArrow $ app . arr (first unwrapArrow)++instance ArrowLoop k => ArrowLoop (WrappedArrow k) where+ loop = WrapArrow . loop . unwrapArrow ++instance Arrow k => Profunctor (WrappedArrow k) where+ lmap = (^>>)+ rmap = (^<<)++instance Monad m => Profunctor (Kleisli m) where+ lmap k (Kleisli f) = Kleisli (f . k)+ rmap k (Kleisli f) = Kleisli (liftM k . f)++instance Functor w => Profunctor (Cokleisli w) where+ lmap k (Cokleisli f) = Cokleisli (f . fmap k)+ rmap k (Cokleisli f) = Cokleisli (k . f)
+ 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.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ profunctors.cabal view
@@ -0,0 +1,34 @@+name: profunctors+category: Control, Categories+version: 0.1+license: BSD3+cabal-version: >= 1.6+license-file: LICENSE+author: Edward A. Kmett+maintainer: Edward A. Kmett <ekmett@gmail.com>+stability: experimental+homepage: git://github.com/ekmett/profunctors/+copyright: Copyright (C) 2011 Edward A. Kmett+synopsis: Haskell 98 Profunctors+description: Haskell 98 Profunctors+build-type: Simple++source-repository head+ type: git+ location: git://github.com/ekmett/profunctors.git++library+ build-depends: + base >= 4 && < 5.0,+ semigroupoids >= 1.2.2 && <= 1.3,+ comonad >= 1.1 && < 1.2++ if impl(ghc)+ cpp-options: -DGHC_TYPEABLE++ extensions: CPP++ exposed-modules:+ Data.Profunctor++ ghc-options: -Wall