anonymous-sums 0.2.0.0 → 0.2.2.0
raw patch · 4 files changed
+27/−5 lines, 4 files
Files
- ChangeLog +3/−0
- Data/Sums.hs +20/−1
- anonymous-sums.cabal +2/−2
- generate-sums.hs +2/−2
+ ChangeLog view
@@ -0,0 +1,3 @@+Version 0.2.2.0++* added S1
Data/Sums.hs view
@@ -13,10 +13,12 @@ module Data.Sums where import Data.Typeable-import GHC.Generics+import GHC.Generics hiding (S1) -- * Anonymous sum types +data S1 a = S1a a deriving (Eq, Ord, Read, Show, Generic, Typeable)+ data S2 a b = S2a a | S2b b deriving (Eq, Ord, Read, Show, Generic, Typeable) data S3 a b c = S3a a | S3b b | S3c c deriving (Eq, Ord, Read, Show, Generic, Typeable)@@ -47,6 +49,12 @@ -- * Partitioning +partitionS1 :: [S1 a] -> ([a])+partitionS1 = foldr fn ([])+ where+ fn it (as) = case it of+ S1a a -> (a:as)+ partitionS2 :: [S2 a b] -> ([a], [b]) partitionS2 = foldr fn ([], []) where@@ -238,6 +246,10 @@ -- * Case analysis +caseS1 :: (a -> z) -> S1 a -> z+caseS1 fa s1 = case s1 of+ S1a a -> fa a+ caseS2 :: (a -> z) -> (b -> z) -> S2 a b -> z caseS2 fa fb s2 = case s2 of S2a a -> fa a@@ -401,6 +413,9 @@ -- * Mapping +mapS1 :: (a -> a1) -> S1 a -> S1 a1+mapS1 a = caseS1 (S1a . a)+ mapS2 :: (a -> a1) -> (b -> b1) -> S2 a b -> S2 a1 b1 mapS2 a b = caseS2 (S2a . a) (S2b . b) @@ -444,6 +459,10 @@ mapS15 a b c d e f g h i j k l m n o = caseS15 (S15a . a) (S15b . b) (S15c . c) (S15d . d) (S15e . e) (S15f . f) (S15g . g) (S15h . h) (S15i . i) (S15j . j) (S15k . k) (S15l . l) (S15m . m) (S15n . n) (S15o . o) -- * Mapping in a Functor++mapS1f :: Functor ftr =>+ (a -> ftr a1) -> S1 a -> ftr (S1 a1)+mapS1f a = caseS1 (fmap S1a . a) mapS2f :: Functor ftr => (a -> ftr a1) -> (b -> ftr b1) -> S2 a b -> ftr (S2 a1 b1)
anonymous-sums.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: anonymous-sums-version: 0.2.0.0+version: 0.2.2.0 synopsis: Anonymous sum types description: Anonymous sum types. Like tuples, but for sum types rather than@@ -16,7 +16,7 @@ category: Data build-type: Simple cabal-version: >=1.10-extra-source-files: README.md+extra-source-files: README.md, ChangeLog library exposed-modules: Data.Sums
generate-sums.hs view
@@ -158,7 +158,7 @@ imports = unlines [ "import Data.Typeable"- , "import GHC.Generics"+ , "import GHC.Generics hiding (S1)" , "" ] @@ -177,7 +177,7 @@ mapFs = "-- * Mapping in a Functor\n\n" ++ concatMap mapDefA vs - vs = [2..i]+ vs = [1..i] usage :: String