packages feed

acme-cofunctor (empty) → 0.1.0.0

raw patch · 4 files changed

+127/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Jasper Van der Jeugt <m@jaspervdj.be>++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 Jasper Van der Jeugt <m@jaspervdj.be> 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
+ acme-cofunctor.cabal view
@@ -0,0 +1,51 @@+Name:          acme-cofunctor+Version:       0.1.0.0+Synopsis:      A Cofunctor is a structure from category theory dual to Functor+License:       BSD3+License-file:  LICENSE+Author:        Jasper Van der Jeugt <m@jaspervdj.be>+Maintainer:    Jasper Van der Jeugt <m@jaspervdj.be>+Copyright:     2014 Jasper Van der Jeugt+Category:      Acme+Build-type:    Simple+Cabal-version: >= 1.10+Homepage:      https://github.com/jaspervdj/acme-cofunctor++Description:+  A 'Cofunctor' is a structure from category theory dual to 'Functor'.++  .++  A 'Functor' is defined by the operation 'fmap':++  .++  > fmap :: (a -> b) -> (f a -> f b)++  .++  This means that its dual must be defined by the following operation:++  .++  > cofmap :: (b -> a) -> (f b -> f a)++  .++  Since beginning his investigations, the author of this package has discovered+  that this pattern is /at least/ as commonly used as 'Functor'. In fact, many+  ubiquitous Haskell types (e.g. @[]@, 'Maybe', @((->) a)@ turn out to have a+  'Cofunctor' instance.++Library+  Exposed-modules:  Data.Cofunctor+  default-language: Haskell98+  Ghc-options:      -Wall+  Hs-source-dirs:   src++  Build-depends:+    base >= 4 && < 5++Source-repository head+  Type:     git+  Location: https://github.com/jaspervdj/acme-cofunctor
+ src/Data/Cofunctor.hs view
@@ -0,0 +1,44 @@+-- | 'Cofunctor' is a structure from category theory dual to 'Functor'+--+-- A 'Functor' is defined by the operation 'fmap':+--+-- > fmap :: (a -> b) -> (f a -> f b)+--+-- This means that its dual must be defined by the following operation:+--+-- > cofmap :: (b -> a) -> (f b -> f a)+--+-- Since beginning his investigations, the author of this package has discovered+-- that this pattern is /at least/ as commonly used as 'Functor'. In fact, many+-- ubiquitous Haskell types (e.g. @[]@, 'Maybe', @((->) a)@ turn out to have a+-- 'Cofunctor' instance.+module Data.Cofunctor+    ( Cofunctor (..)+    ) where++import Control.Monad (liftM)++-- | 'Cofunctor' is a structure from category theory dual to 'Functor'+class Cofunctor f where+    cofmap :: (b -> a) -> f b -> f a++instance Cofunctor [] where+    cofmap _ []       = []+    cofmap f (x : xs) = f x : cofmap f xs++instance Cofunctor Maybe where+    cofmap _ Nothing  = Nothing+    cofmap f (Just x) = Just (f x)++instance Cofunctor (Either e) where+    cofmap _ (Left e)  = Left e+    cofmap f (Right x) = Right (f x)++instance Cofunctor ((->) a) where+    cofmap = (.)++instance Cofunctor ((,) a) where+    cofmap f (e, x) = (e, f x)++instance Cofunctor IO where+    cofmap = liftM