From 0cbbe31c5f16df73dcc3a73b37cac4a72948f3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Thu, 27 Aug 2026 20:34:57 +0200 Subject: Accept various builtin types in type expressions --- src/Parser/Core.hs | 10 ++++++++++ src/Parser/Expr.hs | 8 +------- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src/Parser') diff --git a/src/Parser/Core.hs b/src/Parser/Core.hs index 37c6f12..c982319 100644 --- a/src/Parser/Core.hs +++ b/src/Parser/Core.hs @@ -95,6 +95,7 @@ data Toplevel data TestParserState = TestParserState { testSourcePath :: FilePath , testVars :: [ ( VarName, ( FqVarName, SomeExprType )) ] + , testTypeVars :: [ ( VarName, SomeExprType ) ] , testContext :: SomeExpr , testNextTypeVar :: Int , testTypeUnif :: Map TypeVar SomeExprType @@ -141,6 +142,15 @@ lookupScalarVarExpr off sline name = do SomeExpr <$> unifyExpr off pa (FunVariable args sline fqn :: Expr (FunctionType a)) stype -> return $ SomeExpr $ DynVariable stype sline fqn +lookupType :: Int -> VarName -> TestParser SomeExprType +lookupType off name = do + gets (lookup name . testTypeVars) >>= \case + Nothing -> do + registerParseError $ FancyError off $ S.singleton $ ErrorFail $ T.unpack $ + "type not in scope: ‘" <> textVarName name <> "’" + return $ ExprTypeVar (TypeVar $ textVarName name) + Just x -> return x + resolveKnownTypeVars :: SomeExprType -> TestParser ( SomeExprType, [ TypeVar ] ) resolveKnownTypeVars = fmap (fmap (uniq . sort)) . runWriterT . go diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs index ec5e2b4..4603dda 100644 --- a/src/Parser/Expr.hs +++ b/src/Parser/Expr.hs @@ -561,10 +561,4 @@ typeExpr :: TestParser SomeExprType typeExpr = do off <- stateOffset <$> getParserState name <- constrName "type constructor name" - - case textVarName name of - "String" -> return $ ExprTypePrim @Text Proxy - _ -> do - registerParseError $ FancyError off $ S.singleton $ ErrorFail $ T.unpack $ - "type constructor not in scope: ‘" <> textVarName name <> "’" - ExprTypeVar <$> newTypeVar + lookupType off name -- cgit v1.2.3