[Haskell-cafe] ErrorT and catchError question
Jonathan Cast
jonathanccast at fastmail.fm
Tue Jan 15 23:07:38 EST 2008
On 15 Jan 2008, at 7:54 PM, Adam Smyczek wrote:
>
> On Jan 15, 2008, at 7:34 PM, Brandon S. Allbery KF8NH wrote:
>
>>
>> On Jan 15, 2008, at 22:05 , Adam Smyczek wrote:
>>
>>> Ups, resend, first response did not make into the list.
>>> On Jan 14, 2008, at 9:33 PM, Brandon S. Allbery KF8NH wrote:
>>>
>>>>
>>>> On Jan 15, 2008, at 0:28 , Adam Smyczek wrote:
>>>>
>>>>> It's probably a trivial question, but I cannot figure out
>>>>> how to implement the catchError function in:
>>>>>
>>>>> instance MonadError String Shell where
>>>>> throwError = error . ("Shell failed: "++)
>>>>> catchError l h = ???
>>>>
>>>> Take a look at Control.Exception.catch for starters.
>>>
>>> No, did not help and
>>> going over the source code of Control.Monad.Error did not
>>> help as well. Does someone have other tips for me?
>>
>> Perhaps you could explain what you're looking for? Your typeclass
>> doesn't tell us anything about the semantics.
>
> The type declaration:
>
> newtype Loader a = Loader
> { load :: ErrorT String IO a }
> deriving (Functor, Monad, MonadIO)
>
> instance MonadError String Loader where
> throwError = error . ("Error: " ++)
I don't think this is what you want; you're throwing away the benefit
of using ErrorT. You probably want
throwError = Loader . throwError
> l `catchError` h = ??? how do I implement this ???
l `catchError` h = Loader (load l `catchError` load . h)
jcc
More information about the Haskell-Cafe
mailing list