From da70b8021ff08d2f994597a9f01289cf4cc04adb Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 15 Oct 2020 16:02:17 +0530 Subject: improve arity error messages - now includes function name with expected arity - closes #4 on github.com/dscrv/lisk --- src/Error/Base.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/Error') diff --git a/src/Error/Base.hs b/src/Error/Base.hs index 509377b..d7b685c 100644 --- a/src/Error/Base.hs +++ b/src/Error/Base.hs @@ -12,7 +12,7 @@ import Text.ParserCombinators.Parsec data LispError = Parse ParseError | BadForm String Expr - | ArgCount Int [Expr] + | ArgCount String Int [Expr] | UnknownFunction String | TypeMismatch String Expr @@ -22,7 +22,10 @@ unwordsList = unwords . map show instance Show LispError where show (Parse e) = "Parser Error: " ++ show e show (BadForm s expr) = "Bad Form: " ++ s ++ ": " ++ show expr - show (ArgCount n es) = "Invalid arity, expected " ++ show n ++ ", got value(s): " ++ unwordsList es + -- TODO: clean this up + show (ArgCount fn n es) + | null es = "Invalid arity, `" ++ fn ++ "` expects " ++ show n ++ " or more expression(s)!" + | otherwise = "Invalid arity, `" ++ fn ++ "` expects " ++ show n ++ " or more expression(s), got value(s): " ++ unwordsList es show (UnknownFunction fn) = "Cannot apply function: " ++ fn show (TypeMismatch msg got) = "Type mismatch, expected " ++ msg ++ ", got: " ++ show got -- cgit v1.2.3