packages feed

acme-schoenfinkel (empty) → 0.1.0

raw patch · 6 files changed

+230/−0 lines, 6 filesdep +QuickCheckdep +acme-schoenfinkeldep +basesetup-changed

Dependencies added: QuickCheck, acme-schoenfinkel, base, test-framework, test-framework-quickcheck2, test-framework-th

Files

+ Control/Category/Schoenfinkel.hs view
@@ -0,0 +1,98 @@+-- |+-- Module:     Control.Category.Schoenfinkel+-- Copyright:  (c) 2013 Ertugrul Soeylemez+-- License:    BSD3+-- Maintainer: Ertugrul Soeylemez <es@ertes.de>+--+-- This library generalizes 'curry' and 'uncurry' and also gives them+-- more appropriate names.+--+-- > import Control.Category.Schoenfinkel+-- >+-- > main :: IO ()+-- > main = print (unschoen atan2 (2, 3))+--+-- For your convenience there are also Unicode variants of both the+-- 'Schoenfinkel' class and its two functions.++module Control.Category.Schoenfinkel+    ( -- * Schoenfinkelization+      Schoenfinkel(..),++      -- * ArrowApply-based+      WrappedSchoenfinkel(..),++      -- * Unicode variants+      Schönfinkel,+      WrappedSchönfinkel,+      schön,+      unschön+    )+    where++import Control.Applicative+import Control.Category+import Control.Arrow+import Prelude hiding ((.), id)+++-- | Categories that support Schönfinkelization.++class (Category cat) => Schoenfinkel cat where+    schoen :: cat (a, b) c -> cat a (cat b c)+    unschoen :: cat a (cat b c) -> cat (a, b) c++instance Schoenfinkel (->) where+    schoen = curry+    unschoen = uncurry++instance (Monad m) => Schoenfinkel (Kleisli m) where+    schoen (Kleisli f) =+        Kleisli $ \x ->+            return (Kleisli $ \y -> f (x, y))++    unschoen (Kleisli f) =+        Kleisli $ \(x, y) ->+            f x >>= ($ y) . runKleisli+++-- | Every 'ArrowApply' gives rise to a 'Schoenfinkel'.++newtype WrappedSchoenfinkel cat a b =+    WrappedSchoenfinkel {+      unwrapSchoenfinkel :: cat a b+    }+    deriving (Alternative, Applicative, Arrow, ArrowApply,+              ArrowChoice, ArrowLoop, ArrowPlus, ArrowZero,+              Category, Functor)++instance (ArrowApply cat) => Schoenfinkel (WrappedSchoenfinkel cat) where+    schoen (WrappedSchoenfinkel c) =+        WrappedSchoenfinkel $+            arr (\x -> WrappedSchoenfinkel $ c . arr ((,) x))++    unschoen (WrappedSchoenfinkel c) =+        WrappedSchoenfinkel $+            app . arr (first unwrapSchoenfinkel) . first c+++-- | Unicode version of 'Schoenfinkel' if you prefer.++type Schönfinkel = Schoenfinkel+++-- | Unicode version of 'WrappedSchoenfinkel' if you prefer.++type WrappedSchönfinkel = WrappedSchoenfinkel+++-- | Unicode version of 'schoen' if you prefer.++schön :: (Schoenfinkel cat) => cat (a, b) c -> cat a (cat b c)+schön = schoen+++-- | Unicode version of 'unschoen' if you prefer.++unschön :: (Schoenfinkel cat) => cat a (cat b c) -> cat (a, b) c+unschön = unschoen
+ LICENSE view
@@ -0,0 +1,32 @@+acme-schoenfinkel license+Copyright (c) 2013, Ertugrul Soeylemez++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 the author nor the names of any 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.
+ README.md view
@@ -0,0 +1,16 @@+acme-schoenfinkel+=================++This library generalizes `curry` and `uncurry` and also gives them more+appropriate names.  You can use it by importing+`Control.Category.Schoenfinkel`:++    import Control.Category.Schoenfinkel++    main :: IO ()+    main = print (unschoen atan2 (2, 3))++For your convenience there are also Unicode variants of the two+functions:++    main = print (unschön atan2 (2, 3))
+ Setup.lhs view
@@ -0,0 +1,12 @@+acme-schoenfinkel setup script+Copyright (C) 2013, Ertugrul Soeylemez++Please see the LICENSE file for terms and conditions of use,+modification and distribution of this package, including this file.++> module Main where+>+> import Distribution.Simple+>+> main :: IO ()+> main = defaultMain
+ acme-schoenfinkel.cabal view
@@ -0,0 +1,46 @@+name:          acme-schoenfinkel+version:       0.1.0+category:      Acme+synopsis:      Proper names for curry and uncurry+maintainer:    Ertugrul Söylemez <es@ertes.de>+author:        Ertugrul Söylemez <es@ertes.de>+copyright:     (c) 2013 Ertugrul Söylemez+license:       BSD3+license-file:  LICENSE+build-type:    Simple+cabal-version: >= 1.10+extra-source-files: README.md+description:+    This package implements curry and uncurry with their proper names:+    schoen and unschoen.++Source-repository head+    type:     darcs+    location: http://hub.darcs.net/ertes/acme-schoenfinkel++library+    build-depends:+        base >= 4.5 && < 5+    default-language: Haskell2010+    default-extensions:+        ConstraintKinds+        GeneralizedNewtypeDeriving+    ghc-options: -W+    exposed-modules:+        Control.Category.Schoenfinkel++test-suite tests+    type: exitcode-stdio-1.0+    build-depends:+        base >= 4.5 && < 5,+        acme-schoenfinkel,+        QuickCheck,+        test-framework,+        test-framework-quickcheck2,+        test-framework-th+    default-language: Haskell2010+    default-extensions:+        TemplateHaskell+    ghc-options: -W -threaded -rtsopts -with-rtsopts=-N+    hs-source-dirs: test+    main-is: Props.hs
+ test/Props.hs view
@@ -0,0 +1,26 @@+-- |+-- Module:     Main+-- Copyright:  (c) 2013 Ertugrul Soeylemez+-- License:    BSD3+-- Maintainer: Ertugrul Soeylemez <es@ertes.de>++module Main where++import Control.Category.Schoenfinkel+import Test.Framework.Providers.QuickCheck2+import Test.Framework.TH+import Test.QuickCheck.Function+++prop_schoen :: Fun (Int, Int) Int -> Int -> Int -> Bool+prop_schoen (Fun _ f) x y = schoen f x y == curry f x y+++prop_unschoen :: Fun Int (Fun Int Int) -> Int -> Int -> Bool+prop_unschoen (Fun _ f') x y =+    let f = apply . f'+    in unschoen f (x, y) == uncurry f (x, y)+++main :: IO ()+main = $(defaultMainGenerator)