express 1.0.4 → 1.0.6
raw patch · 7 files changed
+185/−9 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Express.Fixtures: div' :: Expr -> Expr -> Expr
+ Data.Express.Fixtures: divE :: Expr
+ Data.Express.Fixtures: init' :: Expr -> Expr
+ Data.Express.Fixtures: mod' :: Expr -> Expr -> Expr
+ Data.Express.Fixtures: modE :: Expr
+ Data.Express.Fixtures: oo :: Expr -> Expr -> Expr
+ Data.Express.Fixtures: ooE :: Expr
+ Data.Express.Fixtures: question :: Expr
+ Data.Express.Fixtures: quot' :: Expr -> Expr -> Expr
+ Data.Express.Fixtures: quotE :: Expr
+ Data.Express.Fixtures: rem' :: Expr -> Expr -> Expr
+ Data.Express.Fixtures: remE :: Expr
Files
- README.md +3/−4
- changelog.md +12/−0
- express.cabal +2/−2
- src/Data/Express/Core.hs +4/−2
- src/Data/Express/Fixtures.hs +140/−1
- test/fixtures.hs +23/−0
- test/show.hs +1/−0
README.md view
@@ -416,9 +416,8 @@ For more examples, see the [eg](eg) and [bench](bench) folders. -Express is subject to a paper-"[Express: Applications of Dynamically Typed Haskell Expressions](https://matela.com.br/express.pdf)"-(2021).+Express is subject to a paper in the Haskell Symposium 2021 titled+"[Express: Applications of Dynamically Typed Haskell Expressions](https://matela.com.br/express.pdf)". [Express's Haddock documentation]: https://hackage.haskell.org/package/express/docs/Data-Express.html@@ -436,7 +435,7 @@ [LeanCheck]: https://hackage.haskell.org/package/leancheck [Extrapolate]: https://hackage.haskell.org/package/extrapolate [Speculate]: https://hackage.haskell.org/package/speculate-[Conjure]: https://hackage.haskell.org/package/conjure+[Conjure]: https://hackage.haskell.org/package/code-conjure [u-Speculate]: eg/u-speculate.hs [u-Extrapolate]: eg/u-extrapolate.hs
changelog.md view
@@ -2,6 +2,18 @@ ===================== +v1.0.6+------++* fix pretty printing of unapplied infixed variable functions:+ use `f :: ...` instead of ``(`f`) :: ...``++* `Data.Express.Fixtures`:+ add `init'`, `div'`, `mod'`, `quot'`, `rem'`, `question` and `oo`.++* minor fixes in README++ v1.0.4 ------
express.cabal view
@@ -1,6 +1,6 @@ -- Cabal file for express name: express-version: 1.0.4+version: 1.0.6 synopsis: Dynamically-typed expressions involving function application and variables. description: Express is a library for manipulating dynamically typed Haskell expressions.@@ -63,7 +63,7 @@ source-repository this type: git location: https://github.com/rudymatela/express- tag: v1.0.4+ tag: v1.0.6 library exposed-modules: Data.Express
src/Data/Express/Core.hs view
@@ -444,8 +444,10 @@ Right t -> shows t showsPrecExpr :: Int -> Expr -> String -> String-showsPrecExpr d (Value "_" _) = showString "_" -- a hole-showsPrecExpr d (Value ('_':s) _) = showParen (isInfix s) $ showString s -- a variable+showsPrecExpr d (Value "_" _) = showString "_" -- a hole+showsPrecExpr d (Value ('_':s) _) -- a variable+ | isInfixedPrefix s = showString $ toPrefix s+ | otherwise = showParen (isInfix s) $ showString s showsPrecExpr d (Value s _) | isInfixedPrefix s = showString $ toPrefix s showsPrecExpr d (Value s _) | isNegativeLiteral s = showParen (d > 0) $ showString s showsPrecExpr d (Value s _) = showParen sp $ showString s
src/Data/Express/Fixtures.hs view
@@ -129,9 +129,13 @@ , id', const', negate', abs', signum' , plus, times, minus , (-+-), (-*-)+ , divE, modE, quotE, remE+ , div', mod', quot', rem' , ff, ffE , gg, ggE , hh, hhE+ , oo, ooE+ , question , (-?-) , (-$-) , odd'@@ -166,6 +170,7 @@ , tail' , null' , length'+ , init' , elem' , sort' , insert'@@ -618,6 +623,49 @@ err = error $ "(-?-): cannot apply `(?) :: * -> * -> *` to `" ++ show ex ++ "' and `" ++ show ey ++ "'. Unhandled types?" +-- | A variable binary operator @?@ encoded as an 'Expr' (cf. '-?-')+--+-- > > question :$ xx :$ yy+-- > x ? y :: Int+--+-- > > question :$ pp :$ qq+-- > p ? q :: Bool+question :: Expr+question = var "?" (undefined :: Int -> Int -> Int)++-- | A variable binary operator @o@ lifted over the 'Expr' type.+-- Works for 'Int', 'Bool', 'Char', @[Int]@ and 'String'.+--+-- > > xx `oo` yy+-- > x `o` y :: Int+--+-- > > pp `oo` qq+-- > p `o` q :: Bool+--+-- > > xx `oo` qq+-- > *** Exception: (-?-): cannot apply `o :: * -> * -> *` to `x :: Int' and `q :: Bool'. Unhandled types?+oo :: Expr -> Expr -> Expr+ex `oo` ey = fromMaybe err $ ($$ ey) $ headOr err $ mapMaybe ($$ ex)+ [ var "`o`" (undefined :: Int -> Int -> Int)+ , var "`o`" (undefined :: Bool -> Bool -> Bool)+ , var "`o`" (undefined :: Char -> Char -> Char)+ , var "`o`" (undefined :: [Int] -> [Int] -> [Int])+ , var "`o`" (undefined :: String -> String -> String)+ ]+ where+ err = error $ "oo: cannot apply `o :: * -> * -> *` to `"+ ++ show ex ++ "' and `" ++ show ey ++ "'. Unhandled types?"++-- | A variable binary function @o@ encoded as an 'Expr' (cf. 'oo')+--+-- > > ooE :$ xx :$ yy+-- > x `o` y :: Int+--+-- > > ooE :$ pp :$ qq+-- > p `o` q :: Bool+ooE :: Expr+ooE = var "`o`" (undefined :: Int -> Int -> Int)+ -- | The operator '+' for the 'Int' type for use on 'Expr's. (See also 'plus'.) -- -- > > two -+- three@@ -648,7 +696,7 @@ -- | The operator '*' for the 'Int' type lifted over the 'Expr' type. (See also 'times'.) -- -- > > three -*- three--- > 9 :: Int+-- > 3 * 3 :: Int -- -- > > one -*- two -*- three -- > (1 * 2) * 3 :: Int@@ -682,6 +730,74 @@ minus :: Expr minus = value "-" ((-) :: Int -> Int -> Int) +-- | The function 'div' for the 'Int' type lifted over the 'Expr' type. (See also 'mod'.)+--+-- > > six `div'` four+-- > 6 `div` 4 :: Int+div' :: Expr -> Expr -> Expr+ex `div'` ey = divE :$ ex :$ ey++-- | Integer division 'div' encoded as an 'Expr'.+--+-- > > divE :$ two+-- > (2 `div`) :: Int -> Int+--+-- > > divE :$ two :$ three+-- > 2 `div` 3 :: Int+divE :: Expr+divE = value "`div`" (div :: Int -> Int -> Int)++-- | The function 'mod' for the 'Int' type lifted over the 'Expr' type. (See also 'div'.)+--+-- > > six `mod'` four+-- > 6 `mod` 4 :: Int+mod' :: Expr -> Expr -> Expr+ex `mod'` ey = modE :$ ex :$ ey++-- | Integer modulo 'mod' encoded as an 'Expr'.+--+-- > > modE :$ two+-- > (2 `mod`) :: Int -> Int+--+-- > > modE :$ two :$ three+-- > 2 `mod` 3 :: Int+modE :: Expr+modE = value "`mod`" (mod :: Int -> Int -> Int)++-- | The function 'quot' for the 'Int' type lifted over the 'Expr' type. (See also 'rem'.)+--+-- > > six `quot'` four+-- > 6 `quot` 4 :: Int+quot' :: Expr -> Expr -> Expr+ex `quot'` ey = quotE :$ ex :$ ey++-- | Integer quotient 'quot' encoded as an 'Expr'.+--+-- > > quotE :$ two+-- > (2 `quot`) :: Int -> Int+--+-- > > quotE :$ two :$ three+-- > 2 `quot` 3 :: Int+quotE :: Expr+quotE = value "`quot`" (quot :: Int -> Int -> Int)++-- | The function 'rem' for the 'Int' type lifted over the 'Expr' type. (See also 'quot'.)+--+-- > > six `rem'` four+-- > 6 `rem` 4 :: Int+rem' :: Expr -> Expr -> Expr+ex `rem'` ey = remE :$ ex :$ ey++-- | Integer remainder 'rem' encoded as an 'Expr'.+--+-- > > remE :$ two+-- > (2 `rem`) :: Int -> Int+--+-- > > remE :$ two :$ three+-- > 2 `rem` 3 :: Int+remE :: Expr+remE = value "`rem`" (rem :: Int -> Int -> Int)+ -- | Constructs an application of 'id' as an 'Expr'. -- Only works for 'Int', 'Bool', 'Char', 'String', @[Int]@, @[Bool]@. --@@ -1168,6 +1284,29 @@ ] where err = error $ "length': cannot apply `length :: [a] -> a` to `" ++ show exs ++ "'."++-- | List 'init' lifted over the 'Expr' type.+-- Works for the element types 'Int', 'Char' and 'Bool'.+--+-- > > init' $ unit one+-- > init [1] :: [Int]+--+-- > > init' $ unit bee+-- > init "b" :: [Char]+--+-- > > init' $ zero -:- unit two+-- > init [0,2] :: [Int]+--+-- > > evl $ init' $ zero -:- unit two :: [Int]+-- > [0]+init' :: Expr -> Expr+init' exs = headOr err $ mapMaybe ($$ exs)+ [ value "init" (init :: [Int] -> [Int])+ , value "init" (init :: [Char] -> [Char])+ , value "init" (init :: [Bool] -> [Bool])+ ]+ where+ err = error $ "init': unhandled type " ++ show (typ exs) -- | List 'sort' lifted over the 'Expr' type. -- Works for the element types 'Int', 'Char' and 'Bool'.
test/fixtures.hs view
@@ -112,6 +112,14 @@ , show (pp -?- qq) == "p ? q :: Bool" , show (xxs -?- yys) == "xs ? ys :: [Int]" , show (bee -?- cee) == "'b' ? 'c' :: Char"+ , show question == "(?) :: Int -> Int -> Int"+ , show (question :$ twelve) == "(12 ?) :: Int -> Int"+ , show (xx `oo` yy) == "x `o` y :: Int"+ , show (pp `oo` qq) == "p `o` q :: Bool"+ , show (false `oo` true) == "False `o` True :: Bool"+ , show ooE == "o :: Int -> Int -> Int"+ , show (ooE :$ xx) == "(x `o`) :: Int -> Int"+ , show (ooE :$ xx :$ yy) == "x `o` y :: Int" -- Char -- @@ -153,10 +161,12 @@ , show (tail' $ unit bee) == "tail \"b\" :: [Char]" , show (head' $ zero -:- unit two) == "head [0,2] :: Int" , show (tail' $ zero -:- unit two) == "tail [0,2] :: [Int]"+ , show (init' $ zero -:- unit two) == "init [0,2] :: [Int]" , evl (unit one) == [1 :: Int] , evl (head' $ unit one) == (1 :: Int) , evl (tail' $ zero -:- unit two) == ([2] :: [Int])+ , evl (init' $ zero -:- unit two) == ([0] :: [Int]) -- String -- @@ -253,4 +263,17 @@ , show ((pp -...- true) true) == "[p, True .. True] :: [Bool]" , show ((cc -...- dd) zed) == "[c,d..'z'] :: [Char]" , show ((ae -...- dd) cc) == "['a',d..c] :: [Char]"++ , show (twelve `div'` five) == "12 `div` 5 :: Int"+ , show (twelve `mod'` five) == "12 `mod` 5 :: Int"+ , show (twelve `quot'` five) == "12 `quot` 5 :: Int"+ , show (twelve `rem'` five) == "12 `rem` 5 :: Int"+ , evl (twelve `div'` five) == (2 :: Int)+ , evl (twelve `mod'` five) == (2 :: Int)+ , evl (twelve `quot'` five) == (2 :: Int)+ , evl (twelve `rem'` five) == (2 :: Int)+ , evl (negate' twelve `div'` seven) == (-2 :: Int)+ , evl (negate' twelve `mod'` seven) == (2 :: Int)+ , evl (negate' twelve `quot'` seven) == (-1 :: Int)+ , evl (negate' twelve `rem'` seven) == (-5 :: Int) ]
test/show.hs view
@@ -30,6 +30,7 @@ , show (var "f" (undefined :: Int -> Int -> Int)) == "f :: Int -> Int -> Int" , show (var "f" (undefined :: Int -> Int -> Int) :$ one) == "f 1 :: Int -> Int" , show (var "f" (undefined :: Int -> Int -> Int) :$ one :$ two) == "f 1 2 :: Int"+ , show (var "`f`" (undefined :: Int -> Int -> Int)) == "f :: Int -> Int -> Int" , show (var "`f`" (undefined :: Int -> Int -> Int) :$ one) == "(1 `f`) :: Int -> Int" , show (var "`f`" (undefined :: Int -> Int -> Int) :$ one :$ two) == "1 `f` 2 :: Int" , show (one -?- two) == "1 ? 2 :: Int"