Re: Monad Comprehension Sugar
Geoffrey Alan Washburn <[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
Daniel C. Wang wrote:
> I suspect a more useful approach, would be to extend the frontend in a
> more generic (caml4p) style way
> Ideally, you could register and extension with the frontend.
>
> val registerSyntax : (string * string -> Ast.exp) -> unit
>
> registerSyntax ("monad",parse)
>
>
> val test = #monad [(x, y) | x <~ [1,2], y <~ ["a","b"] ]
>
> Geoffrey Alan Washburn wrote:
>> Somewhat related to my other e-mail, I've just finished putting
>> together a patch to SML/NJ to allow monad comprehensions. Here is an
>> example of using it to implement the list monad.
>>
>
> I think such an extension would not be too hard to do in fact, and
> generally useful.
While such an extension would be useful, I disagree that it would be
"not too hard to do" or better for this particular purpose. I was able
to put this together in an hour or so, and then a little more to polish.
Maybe you could write this kind of extension in a few days, but I
expect it would require touching and understanding a significantly
larger portion of the compiler. Enough other languages have list
comprehensions that I don't really see how this is an unusually specific
extension that ought to be done using your registerSyntax proposal anway.
> More importantly, one could even modify the pretty
> printer in a way that you eliminate syntactic extensions in order to be
> backward compatible with other compilers.
My code essentially already does this. If you pretty print the result
of parsing, you get a valid SML97 program.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV