packages feed

hs-functors (empty) → 0.1.0.0

raw patch · 5 files changed

+127/−0 lines, 5 filesdep +basedep +transformerssetup-changed

Dependencies added: base, transformers

Files

+ Data/Functor/Contravariant.hs view
@@ -0,0 +1,48 @@+module Data.Functor.Contravariant where++import Prelude hiding (Functor)++import Control.Applicative.Backwards+import Control.Arrow+import Control.Monad.Trans.Except+import Control.Monad.Trans.Reader+import Control.Monad.Trans.State+import Control.Monad.Trans.Writer+import Data.Function (on)+import qualified Data.Functor as Covar+import Data.Functor.Compose+import Data.Functor.Const+import Data.Functor.Product+import Data.Functor.Reverse+import Data.Functor.Sum+import Data.Monoid (Alt (..))+import Data.Proxy++class Functor f where+    gmap :: (a -> b) -> f b -> f a+    (>$) :: b -> f b -> f a+    (>$) = gmap . const++(>$<) :: Functor f => (a -> b) -> f b -> f a+(>$<) = gmap++newtype Op1 b a = Op1 { op1 :: a -> b }+newtype Op2 b a = Op2 { op2 :: a -> a -> b }++instance Functor (Op1 a) where gmap f (Op1 g) = Op1 (g . f)+instance Functor (Op2 a) where gmap f (Op2 g) = Op2 (g `on` f)+instance Functor (Const a) where gmap _ (Const a) = Const a+instance Functor Proxy where gmap _ Proxy = Proxy+instance (Functor f, Functor g) => Functor (Product f g) where+    gmap f (Pair x y) = Pair (f >$< x) (f >$< y)+instance (Functor f, Functor g) => Functor (Sum f g) where+    gmap f (InL x) = InL (f >$< x)+    gmap f (InR y) = InR (f >$< y)+deriving instance Functor f => Functor (Reverse f)+deriving instance Functor f => Functor (Backwards f)+deriving instance Functor f => Functor (Alt f)+instance Functor f => Functor (ExceptT e f) where gmap f = ExceptT . gmap (fmap f) . runExceptT+instance Functor f => Functor (ReaderT r f) where gmap f = ReaderT . fmap (gmap f) . runReaderT+instance Functor f => Functor (StateT  s f) where+    gmap f = StateT  . (fmap . gmap) (f *** id) . runStateT+instance Functor f => Functor (WriterT w f) where gmap f = WriterT . gmap (f *** id) . runWriterT
+ Data/Profunctor.hs view
@@ -0,0 +1,23 @@+module Data.Profunctor where++import Prelude hiding ((.), id)++import Control.Arrow (Kleisli (..))+import Control.Category+import Control.Monad++class Profunctor p where+    dimap :: (a -> b) -> (c -> d) -> p b c -> p a d+    dimap f g = lmap f . rmap g++    lmap :: (a -> b) -> p b c -> p a c+    lmap f = dimap f id++    rmap :: (b -> c) -> p a b -> p a c+    rmap g = dimap id g++instance Profunctor (->) where+    dimap f g a = g . a . f++instance Monad m => Profunctor (Kleisli m) where+    dimap f g (Kleisli a) = Kleisli (fmap g . a . f)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2017, M Farkas-Dyck++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * 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.++    * Neither the name of M Farkas-Dyck nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"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 COPYRIGHT+OWNER 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
+ hs-functors.cabal view
@@ -0,0 +1,24 @@+name:                hs-functors+version:             0.1.0.0+synopsis:            Functors from products of Haskell and its dual to Haskell+-- description:         +license:             BSD3+license-file:        LICENSE+author:              M Farkas-Dyck+maintainer:          m.farkasdyck@gmail.com+-- copyright:           +category:            Math+build-type:          Simple+cabal-version:       >=1.10++library+  exposed-modules:     Data.Functor.Contravariant+  exposed-modules:     Data.Profunctor+  -- other-modules:       +  -- other-extensions:    +  build-depends:       base >=4.9 && <4.12+                     , transformers >=0.4.2 && <0.6+  -- hs-source-dirs:      +  default-language:    Haskell2010+  default-extensions:  StandaloneDeriving+                     , GeneralizedNewtypeDeriving