generic-constraints (empty) → 1.0.0
raw patch · 6 files changed
+130/−0 lines, 6 filesdep +HUnitdep +basedep +generic-constraintssetup-changed
Dependencies added: HUnit, base, generic-constraints
Files
- CHANGELOG +4/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- generic-constraints.cabal +48/−0
- src/Generics/Constraints.hs +26/−0
- test/unittests.hs +20/−0
+ CHANGELOG view
@@ -0,0 +1,4 @@+CHANGELOG++1.0+ - Extracted generic-constraints from Sjoerd Visscher's & Xia Li-yao's one-liner library, as advised by Sjoerd
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Sjoerd Visscher++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 Sjoerd Visscher 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
+ generic-constraints.cabal view
@@ -0,0 +1,48 @@+Name: generic-constraints+Version: 1.0.0+Synopsis: Constraints via Generic+Description: Write short and concise contexts based on generics+Homepage: https://github.com/yairchu/generic-constraints+Bug-reports: https://github.com/yairchu/generic-constraints/issues+License: BSD3+License-file: LICENSE+Author: Sjoerd Visscher, Xia Li-yao, Yair Chuchem+Maintainer: yairchu@gmail.com+Category: Generics+Build-type: Simple+Cabal-version: >= 1.8++Extra-Source-Files:+ CHANGELOG++Library+ HS-Source-Dirs: src++ Exposed-modules:+ Generics.Constraints++ Build-depends:+ base >= 4.9 && < 5++ ghc-options:+ -Wall+ -Wnoncanonical-monad-instances+ -Wcompat+ -Wincomplete-record-updates+ -Wincomplete-uni-patterns+ -Wredundant-constraints++source-repository head+ type: git+ location: git://github.com/yairchu/generic-constraints.git++Test-suite unittests+ Hs-source-dirs: test+ Main-is: unittests.hs++ Build-depends:+ base+ , HUnit+ , generic-constraints++ Type: exitcode-stdio-1.0
+ src/Generics/Constraints.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE+ PolyKinds+ , TypeFamilies+ , TypeOperators+ , ConstraintKinds+ #-}+module Generics.Constraints (Constraints) where++import Data.Kind (Constraint, Type)+import GHC.Generics++type family Constraints' (t :: Type -> Type) (c :: Type -> Constraint) :: Constraint+type instance Constraints' V1 c = ()+type instance Constraints' U1 c = ()+type instance Constraints' (f :+: g) c = (Constraints' f c, Constraints' g c)+type instance Constraints' (f :*: g) c = (Constraints' f c, Constraints' g c)+type instance Constraints' (f :.: g) c = Constraints' g c+type instance Constraints' Par1 c = ()+type instance Constraints' (Rec1 f) c = ()+type instance Constraints' (K1 i a) c = c a+type instance Constraints' (M1 i t f) c = Constraints' f c++-- | `Constraints` is a constraint type synonym, containing the constraint+-- requirements for an instance for `t` of class `c`.+-- It requires an instance of class `c` for each component of `t`.+type Constraints t c = Constraints' (Rep t) c
+ test/unittests.hs view
@@ -0,0 +1,20 @@+{-# LANGUAGE+ DeriveGeneric+ , StandaloneDeriving+ , UndecidableInstances+#-}++import Generics.Constraints+import GHC.Generics+import Test.HUnit++data T a = T (a Int)+ deriving Generic++deriving instance Constraints (T a) Eq => Eq (T a)+deriving instance Constraints (T a) Ord => Ord (T a)+deriving instance Constraints (T a) Show => Show (T a)++main = runTestTT $ test+ [ assert (T [5] > T [3])+ ]