From fc00cff556372e914d3cf15c39700b4ff7c3541c Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Sun, 2 Nov 2025 21:35:19 +0100 Subject: better rendering for type errors and evaluation --- lambda-calcul/haskell/src/Minilang/Lambda/Unify.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lambda-calcul/haskell/src/Minilang/Lambda/Unify.hs') diff --git a/lambda-calcul/haskell/src/Minilang/Lambda/Unify.hs b/lambda-calcul/haskell/src/Minilang/Lambda/Unify.hs index f3fff04..96e9990 100644 --- a/lambda-calcul/haskell/src/Minilang/Lambda/Unify.hs +++ b/lambda-calcul/haskell/src/Minilang/Lambda/Unify.hs @@ -46,10 +46,17 @@ apply subs t = foldr (\(x, s) -> subst s x) t subs data UnifyError - = MismatchHead Text Text [Type] [Type] - | Circularity Identifier Type + = Circularity Identifier Type deriving (Show, Eq) +render :: UnifyError -> Text +render (Circularity x t) = + "Cannot unify type variable " + <> x + <> " with type " + <> pretty t + <> " due to circularity: The variable already occurs in the type." + unifyOne :: Type -> Type -> Either UnifyError Substitution unifyOne (TyVar x) (TyVar y) = if x == y then Right [] else Right [(x, TyVar y)] unifyOne (f :-> g) (f' :-> g') = -- cgit v1.3.1