From f8c6706d5eefb8e4ebcdee7c963e8fe22fd9efab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 18 Feb 2023 22:56:31 +0100 Subject: Equality operator for lists --- src/Test.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Test.hs') 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 -- cgit v1.2.3