packages feed

anonymous-sums 0.2.2.0 → 0.4.0.0

raw patch · 5 files changed

+180/−34 lines, 5 filesdep ~base

Dependency ranges changed: base

Files

ChangeLog view
@@ -1,3 +1,12 @@+Version 0.4.0.0++* Added Exception instances (requires major version bump)++* Added S0++* Removed Generics instances; including them makes compatibility+  with GHC 7.4 more difficult.  (requires major version bump)+ Version 0.2.2.0 -* added S1+* added S1.  Still debating whether and how to add S0.
Data/Sums.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE EmptyDataDecls #-}  -- Text of this module generated by the generate-sums.hs -- script, included with the source of the anonymous-sums@@ -13,42 +14,60 @@ module Data.Sums where  import Data.Typeable-import GHC.Generics hiding (S1)+import Control.Exception  -- * Anonymous sum types -data S1 a = S1a a deriving (Eq, Ord, Read, Show, Generic, Typeable)+data S0 deriving Typeable -data S2 a b = S2a a | S2b b deriving (Eq, Ord, Read, Show, Generic, Typeable)+instance Eq S0 where _ == _ = undefined+instance Ord S0 where compare _ _ = undefined+instance Read S0 where readsPrec _ = undefined+instance Show S0 where show _ = undefined+instance Exception S0 -data S3 a b c = S3a a | S3b b | S3c c deriving (Eq, Ord, Read, Show, Generic, Typeable)+data S1 a = S1a a deriving (Eq, Ord, Read, Show, Typeable)+instance (Typeable a, Show a) => Exception (S1 a) -data S4 a b c d = S4a a | S4b b | S4c c | S4d d deriving (Eq, Ord, Read, Show, Generic, Typeable)+data S2 a b = S2a a | S2b b deriving (Eq, Ord, Read, Show, Typeable)+instance (Typeable a, Show a, Typeable b, Show b) => Exception (S2 a b) -data S5 a b c d e = S5a a | S5b b | S5c c | S5d d | S5e e deriving (Eq, Ord, Read, Show, Generic, Typeable)+data S3 a b c = S3a a | S3b b | S3c c deriving (Eq, Ord, Read, Show, Typeable)+instance (Typeable a, Show a, Typeable b, Show b, Typeable c, Show c) => Exception (S3 a b c) -data S6 a b c d e f = S6a a | S6b b | S6c c | S6d d | S6e e | S6f f deriving (Eq, Ord, Read, Show, Generic, Typeable)+data S4 a b c d = S4a a | S4b b | S4c c | S4d d deriving (Eq, Ord, Read, Show, Typeable)+instance (Typeable a, Show a, Typeable b, Show b, Typeable c, Show c, Typeable d, Show d) => Exception (S4 a b c d) -data S7 a b c d e f g = S7a a | S7b b | S7c c | S7d d | S7e e | S7f f | S7g g deriving (Eq, Ord, Read, Show, Generic, Typeable)+data S5 a b c d e = S5a a | S5b b | S5c c | S5d d | S5e e deriving (Eq, Ord, Read, Show, Typeable)+instance (Typeable a, Show a, Typeable b, Show b, Typeable c, Show c, Typeable d, Show d, Typeable e, Show e) => Exception (S5 a b c d e) -data S8 a b c d e f g h = S8a a | S8b b | S8c c | S8d d | S8e e | S8f f | S8g g | S8h h deriving (Eq, Ord, Read, Show, Generic)+data S6 a b c d e f = S6a a | S6b b | S6c c | S6d d | S6e e | S6f f deriving (Eq, Ord, Read, Show, Typeable)+instance (Typeable a, Show a, Typeable b, Show b, Typeable c, Show c, Typeable d, Show d, Typeable e, Show e, Typeable f, Show f) => Exception (S6 a b c d e f) -data S9 a b c d e f g h i = S9a a | S9b b | S9c c | S9d d | S9e e | S9f f | S9g g | S9h h | S9i i deriving (Eq, Ord, Read, Show, Generic)+data S7 a b c d e f g = S7a a | S7b b | S7c c | S7d d | S7e e | S7f f | S7g g deriving (Eq, Ord, Read, Show, Typeable)+instance (Typeable a, Show a, Typeable b, Show b, Typeable c, Show c, Typeable d, Show d, Typeable e, Show e, Typeable f, Show f, Typeable g, Show g) => Exception (S7 a b c d e f g) -data S10 a b c d e f g h i j = S10a a | S10b b | S10c c | S10d d | S10e e | S10f f | S10g g | S10h h | S10i i | S10j j deriving (Eq, Ord, Read, Show, Generic)+data S8 a b c d e f g h = S8a a | S8b b | S8c c | S8d d | S8e e | S8f f | S8g g | S8h h deriving (Eq, Ord, Read, Show) -data S11 a b c d e f g h i j k = S11a a | S11b b | S11c c | S11d d | S11e e | S11f f | S11g g | S11h h | S11i i | S11j j | S11k k deriving (Eq, Ord, Read, Show, Generic)+data S9 a b c d e f g h i = S9a a | S9b b | S9c c | S9d d | S9e e | S9f f | S9g g | S9h h | S9i i deriving (Eq, Ord, Read, Show) -data S12 a b c d e f g h i j k l = S12a a | S12b b | S12c c | S12d d | S12e e | S12f f | S12g g | S12h h | S12i i | S12j j | S12k k | S12l l deriving (Eq, Ord, Read, Show, Generic)+data S10 a b c d e f g h i j = S10a a | S10b b | S10c c | S10d d | S10e e | S10f f | S10g g | S10h h | S10i i | S10j j deriving (Eq, Ord, Read, Show) -data S13 a b c d e f g h i j k l m = S13a a | S13b b | S13c c | S13d d | S13e e | S13f f | S13g g | S13h h | S13i i | S13j j | S13k k | S13l l | S13m m deriving (Eq, Ord, Read, Show, Generic)+data S11 a b c d e f g h i j k = S11a a | S11b b | S11c c | S11d d | S11e e | S11f f | S11g g | S11h h | S11i i | S11j j | S11k k deriving (Eq, Ord, Read, Show) -data S14 a b c d e f g h i j k l m n = S14a a | S14b b | S14c c | S14d d | S14e e | S14f f | S14g g | S14h h | S14i i | S14j j | S14k k | S14l l | S14m m | S14n n deriving (Eq, Ord, Read, Show, Generic)+data S12 a b c d e f g h i j k l = S12a a | S12b b | S12c c | S12d d | S12e e | S12f f | S12g g | S12h h | S12i i | S12j j | S12k k | S12l l deriving (Eq, Ord, Read, Show) -data S15 a b c d e f g h i j k l m n o = 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 deriving (Eq, Ord, Read, Show, Generic)+data S13 a b c d e f g h i j k l m = S13a a | S13b b | S13c c | S13d d | S13e e | S13f f | S13g g | S13h h | S13i i | S13j j | S13k k | S13l l | S13m m deriving (Eq, Ord, Read, Show) +data S14 a b c d e f g h i j k l m n = S14a a | S14b b | S14c c | S14d d | S14e e | S14f f | S14g g | S14h h | S14i i | S14j j | S14k k | S14l l | S14m m | S14n n deriving (Eq, Ord, Read, Show)++data S15 a b c d e f g h i j k l m n o = 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 deriving (Eq, Ord, Read, Show)+ -- * Partitioning +partitionS0 :: [S0] -> ()+partitionS0 _ = ()+ partitionS1 :: [S1 a] -> ([a]) partitionS1 = foldr fn ([])   where@@ -246,6 +265,9 @@  -- * Case analysis +caseS0 :: S0 -> z+caseS0 = undefined+ caseS1 :: (a -> z) -> S1 a -> z caseS1 fa s1 = case s1 of   S1a a -> fa a@@ -413,6 +435,9 @@  -- * Mapping +mapS0 :: S0 -> S0+mapS0 = id+ mapS1 :: (a -> a1) -> S1 a -> S1 a1 mapS1 a = caseS1 (S1a . a) @@ -459,6 +484,9 @@ 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++mapS0f :: Functor ftr => S0 -> ftr S0+mapS0f = undefined  mapS1f :: Functor ftr =>   (a -> ftr a1) -> S1 a -> ftr (S1 a1)
+ Makefile view
@@ -0,0 +1,15 @@+Data/Sums.hs : generate-sums.hs+	runghc generate-sums.hs Data.Sums 15 > Data/Sums.hs++clean :+	rm Data/Sums.hs+	runhaskell Setup clean++dist : Data/Sums.hs+	runhaskell Setup configure +	runhaskell Setup sdist++test : Data/Sums.hs sunlight-test.hs+	runghc sunlight-test.hs++.PHONY: clean
anonymous-sums.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                anonymous-sums-version:             0.2.2.0+version:             0.4.0.0 synopsis:            Anonymous sum types description:   Anonymous sum types.  Like tuples, but for sum types rather than@@ -16,18 +16,25 @@ category:            Data build-type:          Simple cabal-version:       >=1.10-extra-source-files: README.md, ChangeLog+extra-source-files: README.md, ChangeLog, Makefile+tested-with: GHC==7.4.1, GHC==7.6.3+source-repository head+  type: git+  location: https://github.com/massysett/anonymous-sums.git ++-- Dependencies reflect ghc 7.6.  ghc 7.4 had a different+-- Generics interface. library   exposed-modules: Data.Sums-  build-depends:       base >=4.6 && <5+  build-depends:       base >=4.5.0.0 && <5   default-language:    Haskell2010   ghc-options: -Wall  Executable generate-sums   main-is: generate-sums.hs   ghc-options: -Wall-  build-depends: base >=4.6 && <5+  build-depends: base >=4.5.0.0 && <5   default-language: Haskell2010   if ! flag (build-generator)     buildable: False@@ -35,3 +42,4 @@ Flag build-generator   Description: Build binary to generate program source   Default: False+
generate-sums.hs view
@@ -7,27 +7,64 @@  dataDeclaration   :: Int-  -- ^ Number of type variables+  -- ^ Number of type variables. Must be at least 0.   -> String-dataDeclaration i =+dataDeclaration i+  | i == 0 = dataDeclaration0+  | otherwise = dataDeclarationN i++dataDeclaration0 :: String+dataDeclaration0 = unlines+  [ "data S0 deriving Typeable"+  , ""+  , "instance Eq S0 where _ == _ = undefined"+  , "instance Ord S0 where compare _ _ = undefined"+  , "instance Read S0 where readsPrec _ = undefined"+  , "instance Show S0 where show _ = undefined"+  , "instance Exception S0"+  , ""+  ]+++dataDeclarationN+  :: Int+  -- ^ Number of type variables.  Must be at least 1.+  -> String+dataDeclarationN i =   "data " ++ sType i ++ " = "   ++ constructors-  ++ " deriving (Eq, Ord, Read, Show, Generic"+  ++ " deriving (Eq, Ord, Read, Show"   ++ (if i <= 7 then ", Typeable)" else ")")-  ++ "\n\n"+  ++ "\n"+  ++ exceptionInstance i   where     constructors = list " | " . map mkConst       $ ls     mkConst l = 'S' : show i ++ l : ' ' : l : []     ls = letters i +exceptionInstance :: Int -> String+exceptionInstance i+  | i > 7 = "\n"+  | otherwise = "instance " ++ constraint+    ++ "Exception (" ++ sType i ++ ")\n\n"+  where+    constraint+      | i == 0 = ""+      | otherwise = "(" ++ list ", " ls ++ ") => "+      where+        ls = map constrain . letters $ i+        constrain c = "Typeable " ++ s ++ ", Show " ++ s+          where s = [c]+ letter :: Int -> Char letter i = toEnum (97 + i)  sType :: Int -> String sType i = 'S' : show i ++ types   where-    types = " " ++ intersperse ' ' ls+    types | i == 0 = ""+          | otherwise = " " ++ intersperse ' ' ls     ls = letters i  letters :: Int -> [Char]@@ -37,7 +74,19 @@ list s = concat . intersperse s  partitionDef :: Int -> String-partitionDef i = sig ++ decl+partitionDef i+  | i == 0 = partitionDef0+  | otherwise = partitionDefN i++partitionDef0 :: String+partitionDef0 = unlines+  [ "partitionS0 :: [S0] -> ()"+  , "partitionS0 _ = ()"+  , ""+  ]++partitionDefN :: Int -> String+partitionDefN i = sig ++ decl   where     sig = fName ++ " :: ["       ++ sType i ++ "] -> " ++ tuple ++ "\n"@@ -69,7 +118,19 @@               | otherwise = ltr : 's' : []  caseDef :: Int -> String-caseDef i = sig ++ decl+caseDef i+  | i == 0 = caseDef0+  | otherwise = caseDefN i++caseDef0 :: String+caseDef0 = unlines+  [ "caseS0 :: S0 -> z"+  , "caseS0 = undefined"+  , ""+  ]++caseDefN :: Int -> String+caseDefN i = sig ++ decl   where     sig = fName ++ " :: " ++ fns       ++ " -> " ++ sType i ++ " -> z\n"@@ -87,7 +148,19 @@       : " -> " ++ ('f' : l : ' ' : l : "\n")  mapDef :: Int -> String-mapDef i = sig ++ decl+mapDef i+  | i == 0 = mapDef0+  | otherwise = mapDefN i++mapDef0 :: String+mapDef0 = unlines+  [ "mapS0 :: S0 -> S0"+  , "mapS0 = id"+  , ""+  ]++mapDefN :: Int -> String+mapDefN i = sig ++ decl   where     fName = "mapS" ++ show i     sig = fName ++ " :: " ++ list " -> "@@ -104,7 +177,19 @@     mkMapper l = "(S" ++ show i ++ l : " . " ++ l : ")"  mapDefA :: Int -> String-mapDefA i = sig ++ decl+mapDefA i+  | i == 0 = mapDefA0+  | otherwise = mapDefAN i++mapDefA0 :: String+mapDefA0 = unlines+  [ "mapS0f :: Functor ftr => S0 -> ftr S0"+  , "mapS0f = undefined"+  , ""+  ]++mapDefAN :: Int -> String+mapDefAN i = sig ++ decl   where     fName = "mapS" ++ show i ++ "f"     sig = fName ++ " :: "@@ -136,7 +221,8 @@   ++ cases ++ maps ++ mapFs   where -    pragmas = "{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}\n\n"+    pragmas = "{-# LANGUAGE DeriveDataTypeable #-}\n"+      ++ "{-# LANGUAGE EmptyDataDecls #-}\n\n"      notice = unlines       [ "-- Text of this module generated by the generate-sums.hs"@@ -158,7 +244,7 @@      imports = unlines       [ "import Data.Typeable"-      , "import GHC.Generics hiding (S1)"+      , "import Control.Exception"       , ""       ] @@ -177,7 +263,7 @@     mapFs = "-- * Mapping in a Functor\n\n"       ++ concatMap mapDefA vs -    vs = [1..i]+    vs = [0..i]  usage   :: String