packages feed

poly-arity (empty) → 0.0.1

raw patch · 5 files changed

+111/−0 lines, 5 filesdep +HListdep +QuickCheckdep +basesetup-changed

Dependencies added: HList, QuickCheck, base, constraints, hspec, quickcheck-instances

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Athan Clark++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 Athan Clark 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
+ poly-arity.cabal view
@@ -0,0 +1,35 @@+Name:                   poly-arity+Version:                0.0.1+Author:                 Athan Clark <athan.clark@gmail.com>+Maintainer:             Athan Clark <athan.clark@gmail.com>+License:                BSD3+License-File:           LICENSE+Synopsis:               Tools for working with functions of undetermined arity+-- Description:+Cabal-Version:          >= 1.10+Build-Type:             Simple++Library+  Default-Language:     Haskell2010+  HS-Source-Dirs:       src+  GHC-Options:          -Wall+  Exposed-Modules:      Data.Function.Poly+  Build-Depends:        base >= 4 && < 5+                      , constraints+                      , HList++Test-Suite spec+  Type:                 exitcode-stdio-1.0+  Default-Language:     Haskell2010+  Hs-Source-Dirs:       src+                      , test+  Ghc-Options:          -Wall+  Main-Is:              Spec.hs+  Build-Depends:        base+                      , hspec+                      , QuickCheck+                      , quickcheck-instances++Source-Repository head+  Type:                 git+  Location:             https://github.com/athanclark/poly-arity.git
+ src/Data/Function/Poly.hs view
@@ -0,0 +1,43 @@+{-# LANGUAGE+    TypeFamilies+  , KindSignatures+  , DataKinds+  , ConstraintKinds+  , TypeOperators+  , MultiParamTypeClasses+  , FunctionalDependencies+  , PolyKinds+  , FlexibleInstances+  , UndecidableInstances+  #-}++module Data.Function.Poly where++import Data.Constraint+import Data.HList+++type family TypeListToArity (xs :: [*]) (r :: *) :: * where+  TypeListToArity '[] r = r -- basis+  TypeListToArity (x ': xs) r = x -> TypeListToArity xs r++type family ExpectArity (xs :: [*]) (f :: *) :: Constraint where+  ExpectArity '[] f = () -- basis+  ExpectArity (x ': xs) (x -> remainder) = ExpectArity xs remainder++type family Head (xs :: [k]) :: k where+  Head (x ': xs) = x++type family Tail (xs :: [k]) :: [k] where+  Tail (x ': xs) = xs+++class ExpectArity xs f => ConsumeArity (xs :: [*]) (f :: *) result | xs f -> result where+  appN :: f -> HList xs -> result++instance ConsumeArity '[] r r where+  appN r _ = r++instance ( ConsumeArity xs f r+         , ExpectArity (x ': xs) (x -> f) )=> ConsumeArity (x ': xs) (x -> f) r where+  appN f (HCons x xs) = appN (f x) xs
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}