express 0.1.0 → 0.1.1
raw patch · 6 files changed
+127/−20 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Express.Utils.List: nubSortBy :: (a -> a -> Ordering) -> [a] -> [a]
+ Data.Express.Utils.Typeable: typesIn :: TypeRep -> [TypeRep]
+ Data.Express.Utils.Typeable: typesInList :: [TypeRep] -> [TypeRep]
Files
- TODO.md +3/−8
- express.cabal +12/−12
- src/Data/Express/Utils/List.hs +10/−0
- src/Data/Express/Utils/Typeable.hs +43/−0
- test/map.hs +6/−0
- test/utils.hs +53/−0
TODO.md view
@@ -3,18 +3,13 @@ Here is a list of things TO DO for express: -* release on Hackage -- this should coincide with a new release for both- Speculate and Extrapolate.---* review `Data.Express` haddock+* review Haddock of `Data.Express` -* document the `Instances` module+* document the `Instances` module,+ including note about linear time on searches * test the `Instances` module * sweep occurrences of `TODO:` throughout source files * Document `test/Test.ListableExpr` module thoroughly;--
express.cabal view
@@ -1,7 +1,7 @@ -- Cabal file for express-name: express-version: 0.1.0-synopsis: Express+name: express+version: 0.1.1+synopsis: Dynamically-typed expressions involving applications and variables. description: Express is a library for manipulating dynamically typed Haskell expressions. It's like @ Data.Dynamic @ but with support for encoding applications and@@ -12,14 +12,14 @@ @ Expr @s. See the README and Haddock documentation for more details. -homepage: https://github.com/rudymatela/express#readme-license: BSD3-license-file: LICENSE-author: Rudy Matela <rudy@matela.com.br>-maintainer: Rudy Matela <rudy@matela.com.br>-category: Testing-build-type: Simple-cabal-version: 1.18+homepage: https://github.com/rudymatela/express#readme+license: BSD3+license-file: LICENSE+author: Rudy Matela <rudy@matela.com.br>+maintainer: Rudy Matela <rudy@matela.com.br>+category: Data+build-type: Simple+cabal-version: 1.18 extra-doc-files: README.md , TODO.md@@ -57,7 +57,7 @@ source-repository this type: git location: https://github.com/rudymatela/express- tag: v0.1.0+ tag: v0.1.1 library exposed-modules: Data.Express
src/Data/Express/Utils/List.hs view
@@ -9,6 +9,7 @@ {-# LANGUAGE CPP #-} module Data.Express.Utils.List ( nubSort+ , nubSortBy , isPermutationOf , isSubsetOf , isNub@@ -44,6 +45,15 @@ nnub [] = [] nnub [x] = [x] nnub (x:xs) = x : nnub (dropWhile (==x) xs)++nubSortBy :: (a -> a -> Ordering) -> [a] -> [a]+nubSortBy cmp = nnub . sortBy cmp+ where+ x -==- y = x `cmp` y == EQ+ -- linear nub of adjacent values+ nnub [] = []+ nnub [x] = [x]+ nnub (x:xs) = x : nnub (dropWhile (-==-x) xs) -- | /O(n log n)/. -- Checks that all elements of the first list are elements of the second.
src/Data/Express/Utils/Typeable.hs view
@@ -22,6 +22,8 @@ , funTyCon , compareTy , elementTy+ , typesIn+ , typesInList , (->::) , module Data.Typeable )@@ -29,6 +31,7 @@ import Data.Typeable import Data.Monoid ((<>))+import Data.Express.Utils.List -- Different versions of Typeable/GHC provide different orderings for TypeReps. -- The following is a version independent ordering, with the following@@ -114,6 +117,46 @@ mkCompareTy :: TypeRep -> TypeRep mkCompareTy a = a ->:: a ->:: orderingTy++-- | /O(n)/.+-- Return all sub types of a given type including itself.+--+-- > > typesIn $ typeOf (undefined :: Int)+-- > [Int]+--+-- > > typesIn $ typeOf (undefined :: Bool)+-- > [Bool]+--+-- > > typesIn $ typeOf (undefined :: [Int])+-- > [ Int+-- > , [Int]+-- > ]+--+-- > > typesIn $ typeOf (undefined :: Int -> Int -> Int)+-- > [ Int+-- > , Int -> Int+-- > , Int -> Int -> Int+-- > ]+--+-- > > typesIn $ typeOf (undefined :: Int -> [Int] -> [Int])+-- > [ Int+-- > , [Int]+-- > , [Int] -> [Int]+-- > , Int -> [Int] -> [Int]+-- > ]+--+-- > > typesIn $ typeOf (undefined :: Maybe Bool)+-- > [ Bool+-- > , Maybe Bool+-- > ]+typesIn :: TypeRep -> [TypeRep]+typesIn t = typesInList [t]++typesInList :: [TypeRep] -> [TypeRep]+typesInList ts = nubSortBy compareTy $ tins ts []+ where+ tin t = (t:) . tins (typeRepArgs t)+ tins ts = foldr (.) id (map tin ts) -- | An infix alias for 'mkFunTy'. It is right associative. (->::) :: TypeRep -> TypeRep -> TypeRep
test/map.hs view
@@ -90,6 +90,12 @@ , (xx -+- yy) //- [(yy,yy -+- zz),(xx,xx -+- yy)] == (xx -+- yy) -+- (yy -+- zz) + , ((xx -+- yy) -+- zz) // [(xx -+- yy, zero)] == (zero -+- zz)+ , (xx -+- (yy -+- zz)) // [(xx -+- yy, zero)] == (xx -+- (yy -+- zz))++ , holds n $ \(SameTypeE e1 e2) -> e1 // [(e1,e2)] == e2+ , holds n $ \(IntE e1) (IntE e2) -> (e1 -+- e1) // [(e1,e2)] == (e2 -+- e2)+ , holds n $ \e -> renameVarsBy id e == e , holds n $ \c e -> (renameVarsBy tail . renameVarsBy (c:)) e == e , renameVarsBy (++ "1") (xx -+- yy) == (var "x1" int -+- var "y1" int)
test/utils.hs view
@@ -24,6 +24,53 @@ , show (mkCompareTy boolTy) == "Bool -> Bool -> Ordering" , show (mkCompareTy intTy) == "Int -> Int -> Ordering" + , showTypesInTypeOf (u :: Int) == ["Int"]+ , showTypesInTypeOf (u :: Bool) == ["Bool"]+ , showTypesInTypeOf (u :: [Int]) == ["Int", "[Int]"]+ , showTypesInTypeOf (u :: [Bool]) == ["Bool", "[Bool]"]+ , showTypesInTypeOf (u :: (Int,Int)) == ["Int", "(Int,Int)"]+ , showTypesInTypeOf (u :: (Bool,Bool)) == ["Bool", "(Bool,Bool)"]+ , showTypesInTypeOf (u :: (Int,Bool)) == ["Bool", "Int", "(Int,Bool)"]+ , showTypesInTypeOf (u :: Maybe Integer) == ["Integer", "Maybe Integer"]+ , showTypesInTypeOf (u :: Int -> Int) == ["Int", "Int -> Int"]+ , showTypesInTypeOf (u :: Int -> Bool) == ["Bool", "Int", "Int -> Bool"]++ , showTypesInTypeOf (u :: Int -> Int -> Int)+ == [ "Int"+ , "Int -> Int"+ , "Int -> Int -> Int"+ ]++ , showTypesInTypeOf (u :: Either String ())+ == [ "()"+ , "Char"+ , "[Char]"+ , "Either [Char] ()"+ ]++ , showTypesInTypeOf (u :: Either String Bool -> Maybe Int -> Int -> Bool)+ == [ "Bool"+ , "Char"+ , "Int"+ , "Maybe Int"+ , "[Char]"+ , "Either [Char] Bool"+ , "Int -> Bool"+ , "Maybe Int -> Int -> Bool"+ , "Either [Char] Bool -> Maybe Int -> Int -> Bool"+ ]++ , map show (typesInList [typeOf (u :: Int), typeOf (u :: Bool)])+ == [ "Bool"+ , "Int"+ ]++ , map show (typesInList [typeOf (u :: Int), typeOf (u :: Int -> Bool)])+ == [ "Bool"+ , "Int"+ , "Int -> Bool"+ ]+ , primeCycle [] == [] , ["x", "y", "z", "x'", "y'", "z'", "x''"] `isPrefixOf` primeCycle ["x","y","z"] , ["x","x'","x''","x'''","x''''","x'''''"] `isPrefixOf` primeCycle ["x"]@@ -51,3 +98,9 @@ , ["thingAndThing", "thingAndThing'", "thingAndThing''", "thingAndThing'''"] `isPrefixOf` variableNamesFromTemplate "thingAndThing" ]++u :: a+u = undefined++showTypesInTypeOf :: Typeable a => a -> [String]+showTypesInTypeOf = map show . typesIn . typeOf