packages feed

express 1.0.2 → 1.0.4

raw patch · 8 files changed

+76/−19 lines, 8 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Express.Express: instance (GHC.Float.RealFloat a, Data.Express.Express.Express a) => Data.Express.Express.Express (Data.Complex.Complex a)
+ Data.Express.Fixtures: (-%-) :: Expr -> Expr -> Expr
+ Data.Express.Name: instance Data.Express.Name.Name (Data.Complex.Complex a)
+ Data.Express.Name: instance Data.Express.Name.Name GHC.Int.Int16
+ Data.Express.Name: instance Data.Express.Name.Name GHC.Int.Int32
+ Data.Express.Name: instance Data.Express.Name.Name GHC.Int.Int64
+ Data.Express.Name: instance Data.Express.Name.Name GHC.Int.Int8
+ Data.Express.Name: instance Data.Express.Name.Name GHC.Unicode.GeneralCategory
+ Data.Express.Name: instance Data.Express.Name.Name GHC.Word.Word16
+ Data.Express.Name: instance Data.Express.Name.Name GHC.Word.Word32
+ Data.Express.Name: instance Data.Express.Name.Name GHC.Word.Word64
+ Data.Express.Name: instance Data.Express.Name.Name GHC.Word.Word8

Files

changelog.md view
@@ -2,6 +2,15 @@ =====================  +v1.0.4+------++* deeply encode `Ratio`s+* add `Express (Complex a)` instance+* add several missing `Name` instances+* `deriveName` now uses `x` for `Num` instances++ v1.0.2 ------ 
express.cabal view
@@ -1,6 +1,6 @@ -- Cabal file for express name: express-version: 1.0.2+version: 1.0.4 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.2+  tag:            v1.0.4  library   exposed-modules:     Data.Express
src/Data/Express/Express.hs view
@@ -32,6 +32,7 @@ import Data.Word import Data.Ratio import Data.Char+import Data.Complex  -- | -- 'Express' typeclass instances provide an 'expr' function@@ -104,15 +105,11 @@ -- instances of further types and arities --  instance (Integral a, Express a) => Express (Ratio a) where-  expr  =  val--- note that the "Integral a" restriction above is needed on GHC <= 7.10+  expr q  =  value "%" ((%) ->>: q) :$ expr (numerator q) :$ expr (denominator q)+-- the "Integral a" restriction above is required for compilation on GHC <= 7.10 --- TODO: deeply encode ratios--- NOTE:--- The following would allow zero denominators--- expr (n % d) = constant "%" ((%) -:> n) :$ expr n :$ expr d--- but that is not our problem here!--- Nevertheless, we should change and see the effect on Extrapolate first...+instance (RealFloat a, Express a) => Express (Complex a) where+  expr (x :+ y)  =  value ":+" ((:+) ->>: (x :+ y)) :$ expr x :$ expr y  instance (Express a, Express b, Express c, Express d, Express e)       => Express (a,b,c,d,e) where
src/Data/Express/Fixtures.hs view
@@ -191,6 +191,9 @@   , quintuple   , sixtuple +  -- ** Ratios+  , (-%-)+   -- ** Higher order   , compose   , mapE@@ -210,6 +213,7 @@ import Data.Typeable (Typeable, typeOf) import Data.Char import Data.List+import Data.Ratio  int :: Int int  =  undefined@@ -1545,6 +1549,15 @@ headOr :: a -> [a] -> a headOr x []     =  x headOr _ (x:_)  =  x++-- | The '%' constructor lifted over 'Expr's.+--+-- > > val (2 :: Integer) -%- val (3 :: Integer)+-- > 2 % 3 :: Ratio Integer+--+--   This only accepts 'Expr's bound to the 'Integer' type.+(-%-) :: Expr -> Expr -> Expr+en -%- ed  =  value "%" ((%) :: Integer -> Integer -> Rational) :$ en :$ ed  -- | Function composition encoded as an 'Expr': --
src/Data/Express/Name.hs view
@@ -14,11 +14,15 @@  import Data.Express.Utils.String -import Data.Char import Data.List-import Data.Ratio (Ratio)-import Data.Word (Word) -- for GHC <= 7.8 +-- for instances:+import Data.Int+import Data.Word+import Data.Ratio+import Data.Complex+import Data.Char+ -- | -- If we were to come up with a variable name for the given type -- what 'name' would it be?@@ -104,6 +108,11 @@ instance Name (Ratio a) where  name _  =  "q"  -- |+-- > name (undefined :: Complex) = "x"+-- > names (undefined :: Complex) = ["x", "y", "z", "x'", ...]+instance Name (Complex a)  where  name _  =  "x"++-- | -- > name (undefined :: Float) = "x" -- > names (undefined :: Float) = ["x", "y", "z", "x'", ...] instance Name Float     where  name _  =  "x"@@ -189,6 +198,16 @@ -- instances of further types and arities --  instance Name Word where  name _  =  "x"++instance Name Int8   where  name _  =  "x"+instance Name Int16  where  name _  =  "x"+instance Name Int32  where  name _  =  "x"+instance Name Int64  where  name _  =  "x"+instance Name Word8  where  name _  =  "x"+instance Name Word16 where  name _  =  "x"+instance Name Word32 where  name _  =  "x"+instance Name Word64 where  name _  =  "x"+instance Name GeneralCategory where  name _  =  "c"  instance (Name a, Name b, Name c, Name d, Name e) => Name (a,b,c,d,e) where   name xyzwv  =  name x ++ name y ++ name z ++ name w ++ name v
src/Data/Express/Name/Derive.hs view
@@ -40,13 +40,13 @@ reallyDeriveName :: Name -> DecsQ reallyDeriveName t  =  do   (nt,vs) <- normalizeType t+  isNum <- t `isInstanceOf` ''Num   [d| instance N.Name $(return nt) where-        name _ = $(stringE vname) |]+        name _  =  $(stringE $ vname isNum) |]   where-  showJustName = reverse . takeWhile (/= '.') . reverse . show-  vname = map toLower . take 1 $ showJustName t--- TODO: on deriveName, use full camelCase name?--- TODO: on deriveName, use x for Num instances?+  showJustName  =  reverse . takeWhile (/= '.') . reverse . show+  vname True   =  "x"+  vname False  =  map toLower . take 1 $ showJustName t  -- Not only really derive Name instances, -- but cascade through argument types.
test/express.hs view
@@ -89,6 +89,11 @@   , expr ((0,False) :: (Int,Bool))  ==  pair zero false   , expr ((True,1)  :: (Bool,Int))  ==  pair true one +  -- Transforming ratios into Exprs+  , expr (1 / 2 :: Rational)  ==  val (1::Integer) -%- val (2::Integer)+  , expr (2 / 3 :: Rational)  ==  val (2::Integer) -%- val (3::Integer)+  , expr (5 / 6 :: Rational)  ==  val (5::Integer) -%- val (6::Integer)+   -- Showing Exprs   , holds n $ \x -> show (expr x) == show (x :: ()) ++ " :: ()"   , holds n $ \x -> show (expr x) == show (x :: Int) ++ " :: Int"
test/name-derive.hs view
@@ -10,6 +10,20 @@ data List a = a :- List a | Nil deriving Show data Bush a = Bush a :-: Bush a | Leaf a deriving (Show, Eq) data Tree a = Node (Tree a) a (Tree a) | Null deriving (Show, Eq)++instance Num Peano where+  Zero + n  =  n+  (Succ n) + m  =  Succ (n + m)+  Zero * n  =  Zero+  (Succ n) * m  =  m + n * m+  abs  =  id+  signum Zero  =  0+  signum (Succ n)  =  1+  fromInteger n  =  iterate Succ Zero !! fromInteger n+  Zero - m  =  Zero+  n - Zero  =  Zero+  Succ n - Succ m  =  n - m+ deriveName ''Peano deriveName ''List deriveName ''Bush@@ -41,7 +55,7 @@ tests n =   [ True -  , name (undefined :: Peano) == "p"+  , name (undefined :: Peano) == "x"   , name (undefined :: List Int) == "l"   , name (undefined :: Bush Int) == "b"   , name (undefined :: Tree Int) == "t"