diff options
Diffstat (limited to 'src/Script/Expr/Class.hs')
| -rw-r--r-- | src/Script/Expr/Class.hs | 12 |
1 files changed, 10 insertions, 2 deletions
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 "<void>" -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 |