Monad of no `return` Proposal (MRP): Moving `return` out of `Monad`

Henrik Nilsson Henrik.Nilsson at nottingham.ac.uk
Fri Sep 25 07:46:53 UTC 2015


Hi,

At least with the current situation, it is possible (from my experience
so far, but I don't claim to have tested extensively) to write code
that works both with the old class hierarchy as well as the new:

   * Add an import Control.Applicative
   * Add an explicit method definition "return = pure" for Monad
     instances
   * Add Applicative to contexts in a few strategic places.

That's a big plus in my books for people who for one reason or another
would like to write code that works against an as broad range of
different versions of the available Haskell tools as possible.

On the other hand, I don't really understand the rationale:

 > Traditionally, `return` is often used where `pure` would suffice
 > today, forcing a `Monad` constraint even if a weaker `Applicative`
 > would have sufficed.
 >
 > As a result, language extensions like `ApplicativeDo`[3] have to
 > rewrite `return` to weaken its `Monad m =>` constraint to
 > `Applicative m =>` in order to benefit existing code at the cost
 > of introducing magic behavior at the type level.

If code is genuinely applicative, why not encourage this to be
clearly signalled by use of "pure" instead of "return"?
Surely that would benefit long-term readability a lot more
than supporting use of the "wrong" function.

And as ApplicativeDo is a new extension, removing the magic
so as to force such a change for code that really is applicative
ought not to cause that much trouble for existing code.

Thus, encourage (or force) people to say what they mean by
using "pure" and "return" appropriately.

I'm thus (very) unconvinced about the merits of this proposal.

Best,

/Henrik

-- 
Henrik Nilsson
School of Computer Science
The University of Nottingham
nhn at cs.nott.ac.uk




This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.



More information about the Libraries mailing list