[Haskell-cafe] Monadic correctness

Derek Elkins derek.a.elkins at gmail.com
Sat Oct 17 16:54:22 EDT 2009


On Sat, Oct 17, 2009 at 3:24 PM, Andrew Coppin
<andrewcoppin at btinternet.com> wrote:
> Edward Z. Yang wrote:
>>
>> Excerpts from Andrew Coppin's message of Sat Oct 17 15:21:28 -0400 2009:
>>
>>>
>>> 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.
>>>
>>
>> A proper monad obeys the monad laws:
>>
>> http://www.haskell.org/haskellwiki/Monad_Laws
>>
>> You can probably cook up some quickcheck properties to test for these,
>> but really you should be able to convince yourself by inspection  that
>> your monad follows these laws.
>>
>
> I'm reasonably confident it works, but not 100% sure...
>
> newtype Foo x = Foo (M -> IO x)

In this case it is trivial, Foo = ReaderT M IO which is a monad.  If
you want, you can verify for yourself that this is a monad.  It isn't,
however, uncommon for custom monads to be (equivalent to) stacks of
monad transformers.


More information about the Haskell-Cafe mailing list