diff options
Diffstat (limited to 'src/Error.hs')
-rw-r--r-- | src/Error.hs | 31 |
1 files changed, 0 insertions, 31 deletions
diff --git a/src/Error.hs b/src/Error.hs deleted file mode 100644 index bfc8d14..0000000 --- a/src/Error.hs +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | module Error ( | ||
2 | LispError (..) | ||
3 | , LispResult (..) | ||
4 | , unwrap | ||
5 | ) where | ||
6 | |||
7 | import Control.Monad.Except | ||
8 | import Parser | ||
9 | import Text.ParserCombinators.Parsec | ||
10 | |||
11 | data LispError = Parse ParseError | ||
12 | | BadForm String Expr | ||
13 | | ArgCount Int [Expr] | ||
14 | | UnknownFunction String | ||
15 | | TypeMismatch String Expr | ||
16 | |||
17 | unwordsList :: [Expr] -> String | ||
18 | unwordsList = unwords . map show | ||
19 | |||
20 | instance Show LispError where | ||
21 | show (Parse e) = "Parser Error: " ++ show e | ||
22 | show (BadForm s expr) = "Bad Form: " ++ s ++ ": " ++ show expr | ||
23 | show (ArgCount n es) = "Invalid arity, expected " ++ show n ++ ", got value(s): " ++ unwordsList es | ||
24 | show (UnknownFunction fn) = "Cannot apply function: " ++ fn | ||
25 | show (TypeMismatch msg got) = "Type mismatch, expected " ++ msg ++ ", got: " ++ show got | ||
26 | |||
27 | type LispResult = Either LispError | ||
28 | |||
29 | unwrap :: LispResult t -> t | ||
30 | unwrap (Right v) = v | ||
31 | unwrap (Left _) = undefined -- should panic | ||