@@ -13,6 +13,7 @@ import Core.Constraints
1313import System.Console.Haskeline
1414import System.Console.Haskeline.MonadException
1515import Control.Monad.State
16+import Control.Monad.Error (throwError, catchError)
1617import System.IO.Error(isUserError, ioeGetErrorString)
1718import Data.Char
1819import Data.Typeable
@@ -21,42 +22,36 @@ iucheck :: Idris ()
2122iucheck = do tit <- typeInType
2223 when (not tit) $
2324 do ist <- getIState
24− idrisCatch (tclift $ ucheck (idris_constraints ist))
25− (\e -> do let msg = show e
26− setErrLine (getErrLine msg)
27− iputStrLn msg)
25+ (tclift $ ucheck (idris_constraints ist)) `idrisCatch`
26+ (\e -> do setErrLine (getErrLine e)
27+ iputStrLn (pshow ist e))
28+
29+showErr :: Err -> Idris String
30+showErr e = getIState >>= return . flip pshow e
31+
2832
2933report :: IOError -> String
3034report e
3135 | isUserError e = ioeGetErrorString e
3236 | otherwise = show e
3337
34−idrisCatch :: Idris a -> (SomeException -> Idris a) -> Idris a
35−idrisCatch = catch
38+--idrisCatch :: Idris a -> (SomeException -> Idris a) -> Idris a
39+--idrisCatch = catch
3640
37−data IdrisErr = IErr String
38− deriving Typeable
41+idrisCatch :: Idris a -> (Err -> Idris a) -> Idris a
42+idrisCatch = catchError
3943
40−instance Show IdrisErr where
41− show (IErr s) = s
42−
43−instance Exception IdrisErr
4444
4545ifail :: String -> Idris ()
46−ifail str = throwIO (IErr str)
46+ifail = throwError . Msg
4747
4848ierror :: Err -> Idris a
49−ierror err = do i <- getIState
50− throwIO (IErr $ pshow i err)
49+ierror = throwError
5150
5251tclift :: TC a -> Idris a
53−tclift tc = case tc of
54− OK v -> return v
55− Error err -> do i <- getIState
56− case err of
57− At (FC f l) e -> setErrLine l
58− _ -> return ()
59− throwIO (IErr $ pshow i err)
52+tclift (OK v) = return v
53+tclift (Error err@(At (FC f l) e)) = do setErrLine l ; throwError err
54+tclift (Error err) = throwError err
6055
6156tctry :: TC a -> TC a -> Idris a
6257tctry tc1 tc2
@@ -64,10 +59,8 @@ tctry tc1 tc2
6459 OK v -> return v
6560 Error err -> tclift tc2
6661
67−getErrLine str
68− = case span (/=':') str of
69− (_, ':':rest) -> case span isDigit rest of
70− ([], _) -> 0
71− (num, _) -> read num
72− _ -> 0
62+getErrLine :: Err -> Int
63+getErrLine (At (FC _ l) _) = l
64+getErrLine _ = 0
65+
7366