summaryrefslogtreecommitdiff
path: root/src/Test.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-02-18 22:56:31 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2023-02-19 21:51:00 +0100
commitf8c6706d5eefb8e4ebcdee7c963e8fe22fd9efab (patch)
tree4823a85427ba6a21b58b48cb5da4bc02b894d99a /src/Test.hs
parent4603b8e9b1d2b99b8286c82d55ac18ba00fe7331 (diff)
Equality operator for lists
Diffstat (limited to 'src/Test.hs')
-rw-r--r--src/Test.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Test.hs b/src/Test.hs
index b6a85ae..88be0dc 100644
--- a/src/Test.hs
+++ b/src/Test.hs
@@ -8,6 +8,7 @@ module Test (
ExprType(..),
SomeVarValue(..), fromSomeVarValue, textSomeVarValue,
RecordSelector(..),
+ ExprListUnpacker(..),
Expr(..), eval, gatherVars,
Regex(RegexPart, RegexString), regexMatch,
@@ -70,6 +71,9 @@ class Typeable a => ExprType a where
recordMembers :: [(Text, RecordSelector a)]
recordMembers = []
+ exprListUnpacker :: proxy a -> Maybe (ExprListUnpacker a)
+ exprListUnpacker _ = Nothing
+
instance ExprType Integer where
textExprType _ = T.pack "integer"
textExprValue x = T.pack (show x)
@@ -101,6 +105,8 @@ instance ExprType a => ExprType [a] where
textExprValue x = "[" <> T.intercalate ", " (map textExprValue x) <> "]"
emptyVarValue = []
+ exprListUnpacker _ = Just $ ExprListUnpacker id (const Proxy)
+
data SomeVarValue = forall a. ExprType a => SomeVarValue a
data RecordSelector a = forall b. ExprType b => RecordSelector (a -> b)
@@ -112,6 +118,8 @@ fromSomeVarValue name (SomeVarValue value) = maybe (fail err) return $ cast valu
textSomeVarValue :: SomeVarValue -> Text
textSomeVarValue (SomeVarValue value) = textExprValue value
+data ExprListUnpacker a = forall e. ExprType e => ExprListUnpacker (a -> [e]) (Proxy a -> Proxy e)
+
data Expr a where
Variable :: ExprType a => VarName -> Expr a