[Ur] Too restrictive syntax sugar for monads (bug #127).

Adam Chlipala adamc at impredicative.com
Sat Feb 18 08:21:18 EST 2012


Alexei Golovko wrote:
> In Haskell 'do { e1; e2 }' expands to 'bind e1 (\_ ->  e2) ' and does not fix "return type" of 'e1'. This is usable, for example, with parser combinators, where we often need call parser and discards its value. Another example --- IO action, which returns some non-interesting technical details (as num of inserted rows or elapsed time).
>
> In Ur, one need noisy 'ignore e1; e2' or (with unused free in 'e2' variable) '_i<- e1; e2' if type 'e1' is not 'm {}'. Does this really help to prevent errors? Which kinds? I am sure, the cost is too large.
>    

Here's a simple example that motivates the design choice:

Version 1 of a library includes function [foo] of type [int -> 
transaction {}].  The function doesn't involve any potential error 
conditions worth considering in client code.

Version 2 of the library changes to [foo : int -> transaction result], 
for some type [result] that includes both successful and error 
outcomes.  Client code will ignore the result, but really we want the 
compiler to help us find all calls whose results now need to be analyzed 
explicitly, to take appropriate action on error cases.  If you look at a 
piece of client code and decide that you don't care about errors there, 
it's simple enough to wrap in [Monad.ignore].  The point is that you had 
to think about each case.

> At least, this difference should be documented in the reference manual: I have thought that improperly declared monad for a some time.
>    

I believe that part of the manual was already fine, but I've added a 
note explicitly calling out the difference from Haskell.  I also 
realized that I hadn't defined the [()] syntax sugar earlier, and that 
was probably the cause of the confusion; so I added that clarification 
elsewhere.  (These changes are in the public Mercurial repo only, ATM.)

> PS. And also fix typo in chapter 4.1, Lexical conventions, of manual.pdf: in the second row of table ASCII representation of long arrow should be '-->' but is '->'
>    

Weird.  The "right" code was there in the source for LaTeX, which 
apparently gets confused by two hyphens in a row.  Fixed now.  Thanks 
for both reports!



More information about the Ur mailing list