aboutsummaryrefslogtreecommitdiff
path: root/src/Error
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-10-15 11:32:17 +0100
committerAkshay <[email protected]>2020-10-15 11:32:17 +0100
commitda70b8021ff08d2f994597a9f01289cf4cc04adb (patch)
treedf62e09aed0e205868ab742a4d8bcea2887fcce7 /src/Error
parent9a5f28025aa5ed89be763dd874590c5ae3cb45b5 (diff)
improve arity error messages
- now includes function name with expected arity - closes #4 on github.com/dscrv/lisk
Diffstat (limited to 'src/Error')
-rw-r--r--src/Error/Base.hs7
1 files changed, 5 insertions, 2 deletions
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
12 12
13data LispError = Parse ParseError 13data LispError = Parse ParseError
14 | BadForm String Expr 14 | BadForm String Expr
15 | ArgCount Int [Expr] 15 | ArgCount String Int [Expr]
16 | UnknownFunction String 16 | UnknownFunction String
17 | TypeMismatch String Expr 17 | TypeMismatch String Expr
18 18
@@ -22,7 +22,10 @@ unwordsList = unwords . map show
22instance Show LispError where 22instance Show LispError where
23 show (Parse e) = "Parser Error: " ++ show e 23 show (Parse e) = "Parser Error: " ++ show e
24 show (BadForm s expr) = "Bad Form: " ++ s ++ ": " ++ show expr 24 show (BadForm s expr) = "Bad Form: " ++ s ++ ": " ++ show expr
25 show (ArgCount n es) = "Invalid arity, expected " ++ show n ++ ", got value(s): " ++ unwordsList es 25 -- TODO: clean this up
26 show (ArgCount fn n es)
27 | null es = "Invalid arity, `" ++ fn ++ "` expects " ++ show n ++ " or more expression(s)!"
28 | otherwise = "Invalid arity, `" ++ fn ++ "` expects " ++ show n ++ " or more expression(s), got value(s): " ++ unwordsList es
26 show (UnknownFunction fn) = "Cannot apply function: " ++ fn 29 show (UnknownFunction fn) = "Cannot apply function: " ++ fn
27 show (TypeMismatch msg got) = "Type mismatch, expected " ++ msg ++ ", got: " ++ show got 30 show (TypeMismatch msg got) = "Type mismatch, expected " ++ msg ++ ", got: " ++ show got
28 31