[Haskell-beginners] error logging

Dennis Raddle dennis.raddle at gmail.com
Tue Dec 20 01:32:42 CET 2011


Okay, I want to write code in the Either monad in order to throw errors
with logging. I did this a while ago but can't find my code and I forget
what I did.

Note that I'm using ghc 6.12.3, which I installed via the haskell platform.

First question is: do I use Control.Monad.Error or Control.Monad.Either?

Second question is: I want to have each monadic function within the stack
of functions that is currently running catch the error and add some context
to the log.

For instance I need to have a function called, let's say,
"catchAndAnnotate" that functions like the following. I'm just making this
up-- how is it really done?

func1 :: SomeType -> Either String SomeType
func1 x = ("running in func1 with argument " ++ show x) `catchAndAnnotate`
  (do y <- somework x
        when (isBad y) (throwError "oops")
        return y)

somework :: SomeType -> Either String SomeType
somework x = ("running in somework with argument ++ show x)
`catchAndAnnotate` (whatever x)

whatever :: SomeType -> Either String SomeType
whatever = ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111219/94415485/attachment.htm>


More information about the Beginners mailing list