packages feed

expressions 0.1.6 → 0.1.7

raw patch · 3 files changed

+13/−3 lines, 3 files

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Change Log +## 0.1.7++* Added simple utility function `toDynamicallySorted`+ ## 0.1.6  * GHC 8.4 compatibility
expressions.cabal view
@@ -1,5 +1,5 @@ name:                expressions-version:             0.1.6+version:             0.1.7 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/Sort.hs view
@@ -28,10 +28,12 @@                             , DynamicSort(..)                             , DynamicallySorted(..)                             , parseSort+                            , toDynamicallySorted                             , toStaticSort                             , toStaticallySorted ) where  import Data.Attoparsec.Text+import Data.Functor import Data.Kind import Data.Singletons import Data.Singletons.Decide@@ -96,6 +98,10 @@         Proved Refl -> Just x         Disproved _ -> Nothing +-- | Converts statically sorted expression to a dynamically sorted one.+toDynamicallySorted :: forall f (s :: Sort). SingI s => IFix f s -> DynamicallySorted f+toDynamicallySorted = DynamicallySorted (sing :: Sing s)+ -- | Tries to convert an expression (`DynamicallySorted`) of some sort to an expression of requested sort. -- Performs no conversions. toStaticallySorted :: forall f (s :: Sort). SingI s => DynamicallySorted f -> Maybe (IFix f s)@@ -107,8 +113,8 @@ -- | Parser that accepts sort definitions such as @bool@, @int@, @array int int@, @array int (array ...)@. parseSort :: Parser DynamicSort parseSort = choice [ bool, int, array ] <?> "Sort" where-        bool  = string "bool" *> pure (DynamicSort SBooleanSort)-        int   = string "int"  *> pure (DynamicSort SIntegralSort)+        bool  = string "bool" $> DynamicSort SBooleanSort+        int   = string "int"  $> DynamicSort SIntegralSort         array = array' <$> (string "array" *> space *> sort') <*> (space *> sort')          sort' = choice [ bool, int, char '(' *> array <* char ')' ]