diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-08-27 20:34:57 +0200 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-08-27 23:04:38 +0200 |
| commit | 0cbbe31c5f16df73dcc3a73b37cac4a72948f3a6 (patch) | |
| tree | f607a68d575ac670b9a637a967eabbe56f9257aa /src/Parser/Core.hs | |
| parent | d8420a37ffe9e752816b071fced4a972ca1fad23 (diff) | |
Accept various builtin types in type expressions
Diffstat (limited to 'src/Parser/Core.hs')
| -rw-r--r-- | src/Parser/Core.hs | 10 |
1 files changed, 10 insertions, 0 deletions
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 |