Monads in Haskell

http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html

says that

“If you hadn’t guessed, this is about monads as they appear in pure functional programming languages like Haskell. They are closely related to the monads of category theory, but are not exactly the same because Haskell doesn’t enforce the identities satisfied by categorical monads.”

What is the point of Haskell monads then, if they do not enforce the monad laws?

As I see, some of them do admit monad laws. But what happens when I use an almost-monad? Do I lose some guarantees?

You probably don’t use an almost-monad. Haskell doesn’t check the monad laws but you’ll pretty much never find a Monad implementation that doesn’t satisfy them.

1 Like

Or at least every monad you use should satisfy the laws up to their public interface, see Haskell Unfolder 8: Laws at around 23:37, they discuss such a case.

I remember once being told-off by filing a bug or something by a package author telling me that “every body knows that M wasn’t a true monad and I shouldn’t be doing what I was trying to do”.
I think I was trying to build some Html using Blaze and Vector. I dont’ remember which monad it was …

You have a soft guarantee, by the package author (and the community). Also monad which don’t enforce laws generate bugs pretty quickly, so people will be complaining …

there it is …

4 Likes

@maxigit thanks indeed, that’s instructive