Prototype of 'docase' notation

Hello,! at the Cambridge Hackathon, I started implementing an extension for GHC that adds the 'docase' notation. The notation is a syntactic sugar that can makes it easier to write code that works with monads that have three additional operations (parallel composition, choice and aliasing). Such monads include various moands for parallel and concurrent programming (Par monad, CPH and Orc) as well as other monads such as parsers. The proposal is in details discussed in our Haskell Symposium paper: http://www.cl.cam.ac.uk/~tp322/papers/docase.html (the page also contains link to earlier pre-processor based prototype with a couple of more examples). I created a GHC Trac ticket to track the discussion about the feature: http://hackage.haskell.org/trac/ghc/ticket/5429. A prototype version of the GHC extension is available here: http://github.com/tpetricek/Haskell.Extensions/commits/. I'd love to hear some feedback about the feature and the extension: * Do you think this is a useful extension and do you know about any monads that could benefit from it? * What is the best syntax for the feature? (The notation intentionally resembles 'case' pattern matching, but there are some differences) * The feature adds some aspects of recently added monad comprehensions using do-style syntax, but both 'docase' and monad comprehensions have features that cannot be written using the other. Is that a good desing, or should there be a closer correspondence? * Can anybody review the prototype implementation? (I believe it is a reasonably modular change, so it should not affect the rest of the language, but is there anything missing/incorrect?) Thanks! Tomas

This is interesting.
I think using a slightly different notation would avoid confusion with
matching on tuples. Why not just write
docase a,b,c of
instead of
docase (a,b,c) of
?
Sebastian
On Thu, Aug 25, 2011 at 9:48 PM, Tomas Petricek
Hello,! at the Cambridge Hackathon, I started implementing an extension for GHC that adds the 'docase' notation. The notation is a syntactic sugar that can makes it easier to write code that works with monads that have three additional operations (parallel composition, choice and aliasing). Such monads include various moands for parallel and concurrent programming (Par monad, CPH and Orc) as well as other monads such as parsers.
The proposal is in details discussed in our Haskell Symposium paper: http://www.cl.cam.ac.uk/~tp322/papers/docase.html (the page also contains link to earlier pre-processor based prototype with a couple of more examples). I created a GHC Trac ticket to track the discussion about the feature: http://hackage.haskell.org/trac/ghc/ticket/5429. A prototype version of the GHC extension is available here: http://github.com/tpetricek/Haskell.Extensions/commits/.
I'd love to hear some feedback about the feature and the extension:
* Do you think this is a useful extension and do you know about any monads that could benefit from it? * What is the best syntax for the feature? (The notation intentionally resembles 'case' pattern matching, but there are some differences) * The feature adds some aspects of recently added monad comprehensions using do-style syntax, but both 'docase' and monad comprehensions have features that cannot be written using the other. Is that a good desing, or should there be a closer correspondence? * Can anybody review the prototype implementation? (I believe it is a reasonably modular change, so it should not affect the rest of the language, but is there anything missing/incorrect?)
Thanks! Tomas
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Thanks for the feedback -
Someone already suggested this syntactic change at Hackathon and the GHC patch implements this syntax :-) (see e.g. the snippet at http://hackage.haskell.org/trac/ghc/ticket/5429). The paper used a parenthesized tuple syntax, so earlier examples use that (however, in an earlier draft I used the syntax without parenthesis). An alternative suggestion was to write "docase a | b | c of ...". This is syntactically similar to monad comprehensions, which is a good thing, but I think the syntax looks a bit odd.
I think the syntax "docase a, b, c of ..." is a good trade-off. It may be useful to give a warning when someone writes "docase (a, b, c) of ...". It should be easy to detect and it can give useful explanation.
Tomas
-----Original Message-----
From: Sebastian Fischer [mailto:fischer@nii.ac.jp]
Sent: Friday, August 26, 2011 12:27 PM
To: Tomas Petricek
Cc: glasgow-haskell-users@haskell.org
Subject: Re: Prototype of 'docase' notation
This is interesting.
I think using a slightly different notation would avoid confusion with matching on tuples. Why not just write
docase a,b,c of
instead of
docase (a,b,c) of
?
Sebastian
On Thu, Aug 25, 2011 at 9:48 PM, Tomas Petricek
Hello,! at the Cambridge Hackathon, I started implementing an extension for GHC that adds the 'docase' notation. The notation is a syntactic sugar that can makes it easier to write code that works with monads that have three additional operations (parallel composition, choice and aliasing). Such monads include various moands for parallel and concurrent programming (Par monad, CPH and Orc) as well as other monads such as parsers.
The proposal is in details discussed in our Haskell Symposium paper: http://www.cl.cam.ac.uk/~tp322/papers/docase.html (the page also contains link to earlier pre-processor based prototype with a couple of more examples). I created a GHC Trac ticket to track the discussion about the feature: http://hackage.haskell.org/trac/ghc/ticket/5429. A prototype version of the GHC extension is available here: http://github.com/tpetricek/Haskell.Extensions/commits/.
I'd love to hear some feedback about the feature and the extension:
* Do you think this is a useful extension and do you know about any monads that could benefit from it? * What is the best syntax for the feature? (The notation intentionally resembles 'case' pattern matching, but there are some differences) * The feature adds some aspects of recently added monad comprehensions using do-style syntax, but both 'docase' and monad comprehensions have features that cannot be written using the other. Is that a good desing, or should there be a closer correspondence? * Can anybody review the prototype implementation? (I believe it is a reasonably modular change, so it should not affect the rest of the language, but is there anything missing/incorrect?)
Thanks! Tomas
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
participants (2)
-
Sebastian Fischer
-
Tomas Petricek