From 3a6faf446c2e62add01c5d912a533f20e853ac77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 12 Apr 2026 11:39:29 +0200 Subject: Type constructors --- src/Script/Expr/Class.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/Script/Expr/Class.hs') diff --git a/src/Script/Expr/Class.hs b/src/Script/Expr/Class.hs index 810b0c8..fd128f1 100644 --- a/src/Script/Expr/Class.hs +++ b/src/Script/Expr/Class.hs @@ -1,10 +1,12 @@ module Script.Expr.Class ( ExprType(..), + ExprTypeConstr1(..), RecordSelector(..), ExprListUnpacker(..), ExprEnumerator(..), ) where +import Data.Kind import Data.Maybe import Data.Scientific import Data.Text (Text) @@ -31,6 +33,9 @@ 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 + textExprTypeConstr1 :: proxy a -> Text -> Text + data RecordSelector a = forall b. ExprType b => RecordSelector (a -> b) @@ -74,12 +79,15 @@ instance ExprType Void where textExprType _ = T.pack "void" textExprValue _ = T.pack "" -instance ExprType a => ExprType [a] where - textExprType _ = "[" <> textExprType @a Proxy <> "]" +instance ExprType a => ExprType [ a ] where + textExprType _ = textExprTypeConstr1 @[] Proxy (textExprType @a Proxy) textExprValue x = "[" <> T.intercalate ", " (map textExprValue x) <> "]" exprListUnpacker _ = Just $ ExprListUnpacker id (const Proxy) +instance ExprTypeConstr1 [] where + textExprTypeConstr1 _ x = "[" <> x <> "]" + instance ExprType a => ExprType (Maybe a) where textExprType _ = textExprType @a Proxy <> "?" textExprValue (Just x) = textExprValue x -- cgit v1.2.3