traceM and traceShowM

pepe mnislaih at gmail.com
Fri Oct 16 09:47:19 EDT 2009


But traceM will only work on non-lazy monads, such as Either or Maybe.
On lazy monads, such as the lazy variants of State, Reader and Writer,  
you would need to write

do {() <- traceM msg; ... }

to ensure that the trace statement is output.

Prelude> :set -fno-monomorphism-restriction
Prelude> let m = do { traceM "hola" ; return 6}
Prelude> m
hola
6
Prelude> Data.Maybe.fromJust m
hola
6
Prelude> head m
hola
6
Prelude> Control.Monad.State.evalState m ()
6

Cheers
pepe

On 16/10/2009, at 15:22, Martijn van Steenbergen wrote:

> Hello,
>
> I propose the addition of the following two functions to module  
> Debug.Trace:
>
>> traceM :: Monad m => String -> m ()
>> traceM msg = trace msg (return ())
>> traceShowM :: (Show a, Monad m) => a -> m ()
>> traceShowM = traceM . show
>
> These functions allow tracing in any do-block. I often define them  
> myself; I think they are useful in general.
>
> Deadline: 23 October 2009.
>
> Martijn.
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries



More information about the Libraries mailing list