packages feed

expressions 0.3 → 0.3.1

raw patch · 4 files changed

+15/−2 lines, 4 files

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Change Log +## 0.3.1++* Utility for extracting constants from expressions+ ## 0.3  * Cleanup, GHC 8.6
expressions.cabal view
@@ -1,5 +1,5 @@ name:                expressions-version:             0.3+version:             0.3.1 synopsis:            Expressions and Formulae a la carte description:   This package is aimed at providing means of fixing a first-order language and
src/Data/Expression.hs view
@@ -703,7 +703,7 @@     not' (Not a) = return . dual . unIFix $ a  freename :: forall f (s :: Sort). ( VarF :<: f, IFunctor f, IFoldable f ) => IFix f s -> String-freename a = head . tail $ dropWhile (\s -> any (>= s) ns) pool where+freename a = head $ dropWhile (\s -> any (>= s) ns) pool where     fs = vars a     ns = sort $ map (\(DynamicallySorted _ (IFix (Var n _))) -> takeWhile (`elem` ['a'..'z']) n) fs 
src/Data/Expression/Arithmetic.hs view
@@ -19,6 +19,7 @@  module Data.Expression.Arithmetic ( ArithmeticF(..)                                   , cnst+                                  , cnsts                                   , add                                   , mul                                   , (.+.)@@ -149,6 +150,14 @@ -- | A smart constructor for integer constants cnst :: ArithmeticF :<: f => Int -> IFix f 'IntegralSort cnst = inject . Const++-- | Collects a list of all constants occurring in an expression.+cnsts :: forall f (s :: Sort). ( ArithmeticF :<: f, IFoldable f, IFunctor f, IEq1 f ) => IFix f s -> [IFix f 'IntegralSort]+cnsts = nub . F.getConst . icata cnsts' where+    cnsts' :: forall (s' :: Sort). f (F.Const [IFix f 'IntegralSort]) s' -> F.Const [IFix f 'IntegralSort] s'+    cnsts' a = case prj a of+        Just (Const c) -> F.Const [cnst c]+        _              -> ifold a  mergeConstAdd :: ArithmeticF :<: f => IFix f 'IntegralSort -> (Int, [IFix f 'IntegralSort]) -> (Int, [IFix f 'IntegralSort]) mergeConstAdd e (acc, r) = case match e of