[Haskell-cafe] Problems with Language.Haskell.Interpreter and errors

Daniel Gorín dgorin at dc.uba.ar
Tue Sep 29 10:16:50 EDT 2009


On Sep 29, 2009, at 8:56 AM, Martin Hofmann wrote:

> Hi,
>
> The API of Language.Haskell.Interpreter says, that 'runInterpreter'
>
> runInterpreter :: (MonadCatchIO m, Functor m) =>
> 	InterpreterT m a ->
> 	m (Either InterpreterError a)
>
> returns 'Left' in case of errors and 'GhcExceptions from the  
> underlying
> GHC API are caught and rethrown as this'.
>
>
> What kind of errors do a generate here, why are they not caught by
> runInterpreter and how can I catch them? I assumed to get a 'Left
> InterpreterError' from the first and an error in MonadCatchIO in the
> second.
>
>> :m +Language.Haskell.Interpreter
>> let estr1 = "let lst [a] = a; lst _ = error \"foo\" in lst []"
>> let estr1 = "let lst [a] = a; in lst []"
>> runInterpreter (setImportsQ [("Prelude", Nothing)] >> eval estr1 )
> Right "*** Exception: foo
>> runInterpreter ( eval estr2)
> Right "*** Exception: <interactive>:1:101-111: Non-exhaustive  
> patterns in function lst
>
>
> Thanks a lot
>


InterpreterErrors are those that prevent your to-be-interpreted code  
from "compiling/typechecking". In this case, estr1 is interpreted just  
fine; but the interpreted value is an exception. So I think  Ritght...  
is ok.

You ought to be able to add a Control.Monad.CatchIO.catch clause to  
your interpreter to catch this kind of errors, if you want. I just  
tried it and failed, though, so this is probably a bug. I'll try to  
track it down in more detail.

Thanks for the report!

Daniel



More information about the Haskell-Cafe mailing list