Unbind ">>"! (was Do-notation)

James B. White III (Trey) whitejbiii@ornl.gov
Sat, 30 Mar 2002 00:39:59 -0500


Here's my short manifesto on ">>" and "do" notation. It is based on the 
precedent set with "negate", a precedent that I also support.

">>" should be a member of the "Monad" class, just as "negate" is a 
member of the "Num" class!

Users should have the power to override the default definition of ">>", just 
as they have the power to override the default definition of "negate"!

Haskell compilers should honor user definitions for ">>" and not 
hard-wire ">>= \_ ->", just as they should honor user definitions for 
"negate" and do not hardwire "0 - x"!

I have fixed the December 2001 release of Hugs to follow these principles 
for ">>". (I haven't tested the fix exhaustively. It works on my programs. 
Corrections appreciated!)

Here are the "diffs", before the fix followed by after:

connect.h:
74c74
< extern Name  nameReturn,  nameBind;   /* for translating monad comps     
*/
---
> extern Name  nameReturn,  nameBind, nameSequence; /* for 
translating monad comps     */

type.c:
85c85
< Name nameReturn,  nameBind;           /* for translating monad comps     
*/
---
> Name nameReturn,  nameBind, nameSequence;             /* for 
translating monad comps     */
3267a3268
>       nameSequence    = linkName(">>");

compiler.c:
397c397
<  * do { e; qs }           =>  LETREC _h _ = [ e | qs ] in bind m exp _h
---
>  * do { e; qs }           =>  sequence m e qs
433,442c433,436
<           case DOQUAL :   {   Cell hVar = inventVar();
<                               Cell ld   = cons(pair(singleton(WILDCARD),
<                                                     transDo(m,e,qs1)),
<                                                NIL);
<                               return ap(LETREC,
<                                         pair(singleton(pair(hVar,ld)),
<                                              ap(ap(ap(nameBind,
<                                                       m),
<                                                    translate(snd(q))),
<                                                 hVar)));
---
>           case DOQUAL :   {
>                               return ap(ap(ap(nameSequence, m),
>                                            translate(snd(q))),
>                                         transDo(m,e,qs1));

---
James B. White III (Trey)
Center for Computational Sciences
Oak Ridge National Laboratory
whitejbiii@ornl.gov