[Haskell-cafe] Monadic correctness

David Menendez dave at zednenem.com
Sat Oct 17 15:37:01 EDT 2009

On Sat, Oct 17, 2009 at 3:21 PM, Andrew Coppin
<andrewcoppin at btinternet.com> wrote:
> Suppose we have
>  newtype Foo x
>  instance Monad Foo
>  runFoo :: Foo x -> IO x
> What sort of things can I do to check that I actually implemented this
> correctly? I mean, ignoring what makes Foo special for a moment, how can I
> check that it works correctly as a monad.

Anything which satisfies the monad laws is a monad. In other words, do you have:

    return a >>= f  =  f a
    m >>= return  =  m
    (m >>= f) >>= g  =  m >>= (\a -> f a >>= g)

When I bother, I usually just work out the proofs by hand.

Dave Menendez <dave at zednenem.com>

More information about the Haskell-Cafe mailing list