From c71d109610ea6f299df09d2b794b326fb70f9ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 16 May 2026 13:47:36 +0200 Subject: Separate hide/expose expressions for primitive and function types --- src/Parser/Core.hs | 21 ++++++++------------- src/Parser/Expr.hs | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) (limited to 'src/Parser') diff --git a/src/Parser/Core.hs b/src/Parser/Core.hs index 6f12af1..3a3450b 100644 --- a/src/Parser/Core.hs +++ b/src/Parser/Core.hs @@ -215,19 +215,20 @@ unifyExpr off pa expr = if , ExprTypeForall qvar itype <- stype -> do tvar <- newTypeVar - _ <- unify off (ExprTypePrim (Proxy :: Proxy a)) $ renameVarInType qvar tvar itype + res <- unify off (ExprTypePrim (Proxy :: Proxy a)) $ renameVarInType qvar tvar itype rtype <- M.lookup tvar <$> gets testTypeUnif - return $ TypeApp (Variable sline name) $ fromMaybe (ExprTypeVar tvar) rtype + return $ ExposePrimType $ TypeApp res (fromMaybe (ExprTypeVar tvar) rtype) (Variable sline name) | DynVariable stype sline name <- expr -> do _ <- unify off (ExprTypePrim (Proxy :: Proxy a)) stype return $ Variable sline name - | HideType (ExprTypePrim (_ :: Proxy b'')) (expr' :: Expr b') <- expr - , Just (Refl :: b'' :~: b') <- eqT - -> do - unifyExpr off pa expr' + | HidePrimType (_ :: Expr b') <- expr + -> unifyExpr off pa (ExposePrimType expr :: Expr b') + + | HideFunType args (_ :: Expr (FunctionType b')) <- expr + -> unifyExpr off pa (ExposeFunType args expr :: Expr (FunctionType b')) | TypeLambda tvar t f <- expr -> do @@ -284,13 +285,7 @@ unifySomeExpr off stype sexpr@(SomeExpr (expr :: Expr a)) tvar <- newTypeVar itype' <- unify off stype $ renameVarInType qvar tvar itype rtype <- M.lookup tvar <$> gets testTypeUnif - case itype' of - ExprTypeFunction _ (ExprTypePrim (Proxy :: Proxy r)) -> - return $ SomeExpr (TypeApp expr (fromMaybe (ExprTypeVar tvar) rtype) :: Expr (FunctionType a)) - ExprTypeFunction _ _ -> - return $ SomeExpr (TypeApp expr (fromMaybe (ExprTypeVar tvar) rtype) :: Expr (FunctionType DynamicType)) - _ -> - return $ SomeExpr (TypeApp expr (fromMaybe (ExprTypeVar tvar) rtype) :: Expr DynamicType) + return $ SomeExpr (TypeApp itype' (fromMaybe (ExprTypeVar tvar) rtype) expr) | ExprTypeFunction args res <- stype = case someExprType sexpr of diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs index 16c2b45..c8a9e85 100644 --- a/src/Parser/Expr.hs +++ b/src/Parser/Expr.hs @@ -195,7 +195,7 @@ list = label "list" $ do return $ SomeExpr $ TypeLambda tvar (ExprTypeApp (ExprTypeConstr1 (Proxy :: Proxy [])) [ ExprTypeVar tvar ]) $ \case - (ExprTypePrim (Proxy :: Proxy a)) -> HideType (ExprTypePrim (Proxy @[ a ])) $ Pure ([] :: [ a ]) + (ExprTypePrim (Proxy :: Proxy a)) -> HidePrimType $ Pure ([] :: [ a ]) _ -> Undefined "incomplete type" ,do SomeExpr x <- someExpr FunctionTerm -- cgit v1.2.3