DSH 0.5 → 0.5.3
raw patch · 5 files changed
+143/−42 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Database.DSH: catMaybes :: QA a => Q [Maybe a] -> Q [a]
+ Database.DSH: fromJust :: QA a => Q (Maybe a) -> Q a
+ Database.DSH: fromMaybe :: QA a => Q a -> Q (Maybe a) -> Q a
+ Database.DSH: isJust :: QA a => Q (Maybe a) -> Q Bool
+ Database.DSH: isNothing :: QA a => Q (Maybe a) -> Q Bool
+ Database.DSH: just :: QA a => Q a -> Q (Maybe a)
+ Database.DSH: listToMaybe :: QA a => Q [a] -> Q (Maybe a)
+ Database.DSH: mapMaybe :: (QA a, QA b) => (Q a -> Q (Maybe b)) -> Q [a] -> Q [b]
+ Database.DSH: maybe :: (QA a, QA b) => Q b -> (Q a -> Q b) -> Q (Maybe a) -> Q b
+ Database.DSH: maybeToList :: QA a => Q (Maybe a) -> Q [a]
+ Database.DSH: nothing :: QA a => Q (Maybe a)
Files
- DSH.cabal +1/−1
- src/Database/DSH.hs +1/−0
- src/Database/DSH/Combinators.hs +36/−1
- src/Database/DSH/Data.hs +8/−0
- tests/Main.hs +97/−40
DSH.cabal view
@@ -1,5 +1,5 @@ Name: DSH-Version: 0.5+Version: 0.5.3 Synopsis: Database Supported Haskell Description: This is a Haskell library for database-supported program execution. Using
src/Database/DSH.hs view
@@ -95,4 +95,5 @@ , unzip , fst , snd+ , maybe )
src/Database/DSH/Combinators.hs view
@@ -8,7 +8,7 @@ import Data.Convertible -import Prelude (Eq, Ord, Num, Bool(..), Integer, Double, undefined, error, ($))+import Prelude (Eq, Ord, Num, Bool(..), Integer, Double, Maybe, undefined, error, ($)) -- * Unit @@ -90,6 +90,41 @@ (?) :: (QA a) => Q Bool -> (Q a,Q a) -> Q a (?) c (a,b) = cond c a b++-- * Maybe++listToMaybe :: QA a => Q [a] -> Q (Maybe a)+listToMaybe (Q as) = (Q as) ++maybeToList :: QA a => Q (Maybe a) -> Q [a]+maybeToList (Q ma) = (Q ma)++nothing :: QA a => Q (Maybe a)+nothing = listToMaybe nil++just :: QA a => Q a -> Q (Maybe a)+just a = listToMaybe (singleton a)++isNothing :: QA a => Q (Maybe a) -> Q Bool+isNothing ma = null (maybeToList ma)++isJust :: QA a => Q (Maybe a) -> Q Bool+isJust ma = not (isNothing ma)++fromJust :: QA a => Q (Maybe a) -> Q a+fromJust ma = head (maybeToList ma)++maybe :: (QA a, QA b) => Q b -> (Q a -> Q b) -> Q (Maybe a) -> Q b+maybe b f ma = (isNothing ma) ? (b, f (fromJust (ma)))++fromMaybe :: QA a => Q a -> Q (Maybe a) -> Q a+fromMaybe a ma = (isNothing ma) ? (a, fromJust (ma))++catMaybes :: QA a => Q [Maybe a] -> Q [a]+catMaybes mas = map fromJust (filter isJust mas)++mapMaybe :: (QA a, QA b) => (Q a -> Q (Maybe b)) -> Q [a] -> Q [b]+mapMaybe f as = catMaybes (map f as) -- * List Construction
src/Database/DSH/Data.hs view
@@ -173,6 +173,14 @@ fromNorm (ListN as (ListT _)) = map fromNorm as fromNorm _ = $impossible +instance (QA a) => QA (Maybe a) where+ reify _ = ListT (reify (undefined :: a))+ toNorm Nothing = ListN [] (ListT (reify (undefined :: a)))+ toNorm (Just x) = ListN [toNorm x] (ListT (reify (undefined :: a)))+ fromNorm (ListN [] (ListT _)) = Nothing+ fromNorm (ListN (x : _) (ListT _)) = Just (fromNorm x)+ fromNorm _ = $impossible+ class BasicType a where instance BasicType () where
tests/Main.hs view
@@ -15,6 +15,7 @@ import Test.QuickCheck.Monadic import Data.List+import Data.Maybe import GHC.Exts import Data.Text (Text)@@ -33,9 +34,9 @@ main :: IO () main = do- putStrLn "Basic Types"- putStrLn "-----------"- putStr "unit: "+ putStrLn "Supprted Types"+ putStrLn "--------------"+ putStr "(): " qc prop_unit putStr "Bool: " qc prop_bool@@ -47,7 +48,16 @@ qc prop_integer putStr "Double: " qc prop_double+ putStr "[Integer]: "+ qc prop_list_integer_1+ putStr "[[Integer]]: "+ qc prop_list_integer_2+ putStr "[[[Integer]]]: "+ qc prop_list_integer_3+ putStr "Maybe Integer: "+ qc prop_maybe_integer + putStrLn "" putStrLn "Equality, Boolean Logic and Ordering" putStrLn "------------------------------------"@@ -79,7 +89,7 @@ qc prop_max_integer putStr "max_double: " qc prop_max_double-+ putStrLn "" putStrLn "Tuples" putStrLn "------"@@ -87,7 +97,7 @@ qc prop_fst putStr "snd: " qc prop_snd-+ putStrLn "" putStrLn "Numerics:" putStrLn "-----------"@@ -117,14 +127,30 @@ qc prop_negate_double putStrLn ""+ putStrLn "Maybe"+ putStrLn "-----"+ putStr "maybe: "+ qc prop_maybe+ putStr "isJust: "+ qc prop_isJust+ putStr "isNothing: "+ qc prop_isNothing+ putStr "fromJust: "+ qc prop_fromJust+ putStr "fromMaybe: "+ qc prop_fromMaybe+ putStr "listToMaybe: "+ qc prop_listToMaybe+ putStr "maybeToList: "+ qc prop_maybeToList+ putStr "catMaybes: "+ qc prop_catMaybes+ putStr "mapMaybe: "+ qc prop_mapMaybe++ putStrLn "" putStrLn "Lists" putStrLn "-----"- putStr "[Integer]: "- qc prop_list_1- putStr "[[Integer]]: "- qc prop_list_2- putStr "[[[Integer]]]: "- qc prop_list_3 putStr "head: " qc prop_head putStr "tail: "@@ -137,10 +163,10 @@ qc prop_take putStr "drop: " qc prop_drop- putStr "map_id: "- qc prop_map_id- putStr "filter_True: "- qc prop_filter_True+ putStr "map: "+ qc prop_map+ putStr "filter: "+ qc prop_filter putStr "the: " qc prop_the putStr "last: "@@ -157,10 +183,10 @@ qc prop_reverse putStr "append: " qc prop_append- putStr "groupWith_id: "- qc prop_groupWith_id- putStr "sortWith_id: "- qc prop_sortWith_id+ putStr "groupWith: "+ qc prop_groupWith+ putStr "sortWith: "+ qc prop_sortWith putStr "and: " qc prop_and putStr "or: "@@ -197,14 +223,13 @@ qc prop_notElem putStr "zip: " qc prop_zip- putStr "zipWith_plus: "- qc prop_zipWith_plus+ putStr "zipWith: "+ qc prop_zipWith putStr "unzip: " qc prop_unzip putStr "nub: " qc prop_nub - makeProp :: (Eq b, QA a, QA b, Show a, Show b) => (Q a -> Q b) -> (a -> b)@@ -240,7 +265,7 @@ uncurryQ :: (Q.QA a, Q.QA b) => (Q.Q a -> Q.Q b -> Q.Q c) -> Q.Q (a,b) -> Q.Q c uncurryQ f = uncurry f . Q.view --- * Basic Types+-- * Supported Types prop_unit :: () -> Property prop_unit = makeProp id id@@ -260,6 +285,18 @@ prop_text :: Text -> Property prop_text t = Text.all isPrint t ==> makeProp id id t +prop_list_integer_1 :: [Integer] -> Property+prop_list_integer_1 = makeProp id id++prop_list_integer_2 :: [[Integer]] -> Property+prop_list_integer_2 = makeProp id id++prop_list_integer_3 :: [[[Integer]]] -> Property+prop_list_integer_3 = makeProp id id++prop_maybe_integer :: Maybe Integer -> Property+prop_maybe_integer = makeProp id id+ -- * Equality, Boolean Logic and Ordering prop_infix_and :: (Bool,Bool) -> Property@@ -304,17 +341,37 @@ prop_max_double :: (Double,Double) -> Property prop_max_double = makePropDouble (uncurryQ Q.max) (uncurry max) --- * Lists+-- * Maybe -prop_list_1 :: [Integer] -> Property-prop_list_1 = makeProp id id+prop_maybe :: (Integer, Maybe Integer) -> Property+prop_maybe = makeProp (\a -> Q.maybe (Q.fst a) id (Q.snd a)) (\(i,mi) -> maybe i id mi) -prop_list_2 :: [[Integer]] -> Property-prop_list_2 = makeProp id id+prop_isJust :: Maybe Integer -> Property+prop_isJust = makeProp Q.isJust isJust -prop_list_3 :: [[[Integer]]] -> Property-prop_list_3 = makeProp id id+prop_isNothing :: Maybe Integer -> Property+prop_isNothing = makeProp Q.isNothing isNothing +prop_fromJust :: Maybe Integer -> Property+prop_fromJust mi = isJust mi ==> makeProp Q.fromJust fromJust mi++prop_fromMaybe :: (Integer,Maybe Integer) -> Property+prop_fromMaybe = makeProp (uncurryQ Q.fromMaybe) (uncurry fromMaybe)++prop_listToMaybe :: [Integer] -> Property+prop_listToMaybe = makeProp Q.listToMaybe listToMaybe++prop_maybeToList :: Maybe Integer -> Property+prop_maybeToList = makeProp Q.maybeToList maybeToList++prop_catMaybes :: [Maybe Integer] -> Property+prop_catMaybes = makeProp Q.catMaybes catMaybes++prop_mapMaybe :: [Maybe Integer] -> Property+prop_mapMaybe = makeProp (Q.mapMaybe id) (mapMaybe id)++-- * Lists+ prop_cons :: (Integer, [Integer]) -> Property prop_cons = makeProp (uncurryQ (Q.<|)) (uncurry (:)) @@ -357,20 +414,20 @@ prop_drop :: (Integer, [Integer]) -> Property prop_drop = makeProp (uncurryQ Q.drop) (\(n,l) -> drop (fromIntegral n) l) -prop_map_id :: [Integer] -> Property-prop_map_id = makeProp (Q.map id) (map id)+prop_map :: [Integer] -> Property+prop_map = makeProp (Q.map id) (map id) prop_append :: ([Integer], [Integer]) -> Property prop_append = makeProp (uncurryQ (Q.><)) (\(a,b) -> a ++ b) -prop_filter_True :: [Integer] -> Property-prop_filter_True = makeProp (Q.filter (const $ Q.toQ True)) (filter $ const True)+prop_filter :: [Integer] -> Property+prop_filter = makeProp (Q.filter (const $ Q.toQ True)) (filter $ const True) -prop_groupWith_id :: [Integer] -> Property-prop_groupWith_id = makeProp (Q.groupWith id) (groupWith id)+prop_groupWith :: [Integer] -> Property+prop_groupWith = makeProp (Q.groupWith id) (groupWith id) -prop_sortWith_id :: [Integer] -> Property-prop_sortWith_id = makeProp (Q.sortWith id) (sortWith id)+prop_sortWith :: [Integer] -> Property+prop_sortWith = makeProp (Q.sortWith id) (sortWith id) prop_null :: [Integer] -> Property prop_null = makeProp Q.null null@@ -441,8 +498,8 @@ prop_zip :: ([Integer], [Integer]) -> Property prop_zip = makeProp (uncurryQ Q.zip) (uncurry zip) -prop_zipWith_plus :: ([Integer], [Integer]) -> Property-prop_zipWith_plus = makeProp (uncurryQ $ Q.zipWith (+)) (uncurry $ zipWith (+))+prop_zipWith :: ([Integer], [Integer]) -> Property+prop_zipWith = makeProp (uncurryQ $ Q.zipWith (+)) (uncurry $ zipWith (+)) prop_unzip :: [(Integer, Integer)] -> Property prop_unzip = makeProp Q.unzip unzip