State monads don't respect the monad laws in Haskell

Dylan Thurston dpt@math.harvard.edu
Tue, 14 May 2002 11:19:44 -0400


--4SFOXa2GPu3tIq4H
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, May 14, 2002 at 04:57:12PM +0200, George Russell wrote:
> According to the report
> > Instances of Monad should satisfy the following laws:
> >
> >    return a >>=3D k          =3D k
> >    m >>=3D return            =3D m
> >    m >>=3D (\x -> k x >>=3D h) =3D (m >>=3D k) >>=3D h
> so neither IO nor my events satisfy this.  Up to now I haven't had
> any problems with this.
=20
> Does GHC or any other Haskell compiler actually rely on instances of
> Monad satisfying left identity?  If not, I would suggest dropping
> the requirement, if it can be done without upsetting category
> theorists.  (What the hell, they stole the term "Monad" from
> philosophy and changed its meaning, so why shouldn't we?)

I don't think this is necessarily wise to drop this from the report
altogether.  To me, it seems comparable to associativity of addition
for instances of Num; many instances don't satisfy it (e.g., Float),
but it's a useful guideline to keep in mind.

I've often been bothered by the inconsistent treatment of laws in the
report; why are there laws for functors, monads, and quot/rem and
div/mod, and not much else?  I'm pleased to see that the laws that are
given actually do have exceptions.

--Dylan


--4SFOXa2GPu3tIq4H
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE84SsPVeybfhaa3tcRAkTyAJ9bFUrokrQb+ruXpk2R4cTkNRUCPQCfUIps
PYVOWqEoC5DUqTWJs73xj/Y=
=Zc7/
-----END PGP SIGNATURE-----

--4SFOXa2GPu3tIq4H--