Permalink
Browse files

repo initialized

  • Loading branch information...
0 parents commit 53b59308bcada37b53a7f582c2c69f7ae944d51f @ekmett committed Jan 14, 2011
Showing with 117 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +55 −0 Data/Functor/Contravariant.hs
  3. +30 −0 LICENSE
  4. +7 −0 Setup.lhs
  5. +23 −0 contravariant.cabal
@@ -0,0 +1,2 @@
+_darcs
+dist
@@ -0,0 +1,55 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : Data.Functor.Contravariant
+-- Copyright : (C) 2007-2011 Edward Kmett
+-- License : BSD-style (see the file LICENSE)
+--
+-- Maintainer : Edward Kmett <ekmett@gmail.com>
+-- Stability : provisional
+-- Portability : portable
+--
+----------------------------------------------------------------------------
+
+module Data.Functor.Contravariant (
+ -- * Contravariant Functors
+ Contravariant(..)
+
+ -- * Predicates are contravariant
+ , Predicate(..)
+
+ -- * Orderings are contravariant
+ , Comparison(..)
+ , defaultComparison
+ -- * Equality quotients are contravariant
+ , Equality(..)
+ , defaultEquality
+ ) where
+
+class Contravariant f where
+ contramap :: (a -> b) -> f b -> f a
+
+-- | Predicates are contravariant functors, because you can apply the contramapped function
+-- to the input of the predicate.
+newtype Predicate a = Predicate { getPredicate :: a -> Bool }
+instance Contravariant Predicate where
+ contramap f g = Predicate $ getPredicate g . f
+
+-- | Comparisons are contravariant functors, because you can apply the contramapped function
+-- to each input to the comparison function.
+newtype Comparison a = Comparison { getComparison :: a -> a -> Ordering }
+instance Contravariant Comparison where
+ contramap f g = Comparison $ \a b -> getComparison g (f a) (f b)
+
+-- | Compare using 'compare'
+defaultComparison :: Ord a => Comparison a
+defaultComparison = Comparison compare
+
+-- | Comparisons are contravariant functors, because you can apply the contramapped function
+-- to each input to the equality comparison function.
+newtype Equality a = Equality { getEquality :: a -> a -> Bool }
+instance Contravariant Equality where
+ contramap f g = Equality $ \a b -> getEquality g (f a) (f b)
+
+-- | Check for equality with '=='
+defaultEquality :: Eq a => Equality a
+defaultEquality = Equality (==)
@@ -0,0 +1,30 @@
+Copyright 2007-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.
@@ -0,0 +1,7 @@
+#!/usr/bin/runhaskell
+> module Main (main) where
+
+> import Distribution.Simple
+
+> main :: IO ()
+> main = defaultMain
@@ -0,0 +1,23 @@
+name: contravariant
+category: Control, Data
+version: 0.1.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/contravariant/
+copyright: Copyright (C) 2007-2011 Edward A. Kmett
+synopsis: Haskell 98 contravariant functors
+description: Haskell 98 contravariant functors
+build-type: Simple
+
+source-repository head
+ type: git
+ location: git://github.com/ekmett/contravariant.git
+
+library
+ build-depends: base < 4.5
+ exposed-modules: Data.Functor.Contravariant
+ ghc-options: -Wall

0 comments on commit 53b5930

Please sign in to comment.