diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-04-12 18:29:52 +0200 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-04-13 20:09:27 +0200 |
| commit | c64e161d89c05dcdcb695f365a9147e212f7393f (patch) | |
| tree | 0b6c230cf4f8538b97a026fd1744d7bc12d7f2a5 /src/Script/Expr | |
| parent | 3a6faf446c2e62add01c5d912a533f20e853ac77 (diff) | |
Type deconstruction and matching in unification
Diffstat (limited to 'src/Script/Expr')
| -rw-r--r-- | src/Script/Expr/Class.hs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Script/Expr/Class.hs b/src/Script/Expr/Class.hs index fd128f1..5bf8a4b 100644 --- a/src/Script/Expr/Class.hs +++ b/src/Script/Expr/Class.hs @@ -1,6 +1,7 @@ module Script.Expr.Class ( ExprType(..), ExprTypeConstr1(..), + TypeDeconstructor(..), RecordSelector(..), ExprListUnpacker(..), ExprEnumerator(..), @@ -18,6 +19,9 @@ class Typeable a => ExprType a where textExprType :: proxy a -> Text textExprValue :: a -> Text + matchTypeConstructor :: proxy a -> TypeDeconstructor a + matchTypeConstructor _ = NoTypeDeconstructor + recordMembers :: [(Text, RecordSelector a)] recordMembers = [] @@ -33,9 +37,13 @@ class Typeable a => ExprType a where exprEnumerator :: proxy a -> Maybe (ExprEnumerator a) exprEnumerator _ = Nothing -class (forall b. ExprType b => ExprType (a b)) => ExprTypeConstr1 (a :: Type -> Type) where +class (Typeable a, forall b. ExprType b => ExprType (a b)) => ExprTypeConstr1 (a :: Type -> Type) where textExprTypeConstr1 :: proxy a -> Text -> Text +data TypeDeconstructor a + = NoTypeDeconstructor + | forall c x. (ExprTypeConstr1 c, ExprType x, c x ~ a) => TypeDeconstructor1 (Proxy c) (Proxy x) + data RecordSelector a = forall b. ExprType b => RecordSelector (a -> b) @@ -82,6 +90,7 @@ instance ExprType Void where instance ExprType a => ExprType [ a ] where textExprType _ = textExprTypeConstr1 @[] Proxy (textExprType @a Proxy) textExprValue x = "[" <> T.intercalate ", " (map textExprValue x) <> "]" + matchTypeConstructor _ = TypeDeconstructor1 Proxy Proxy exprListUnpacker _ = Just $ ExprListUnpacker id (const Proxy) |