
Hi, I raised this question on #haskell, and was advised that this was probably the best place to discuss. I see that Applicative Do is scheduled for GHC 8.0 [1], and was hoping that this might also enable support for Applicative Comprehensions [2]. Is this likely to be the case? If not, would it be difficult to extend the support for Applicative Do to also handle comprehensions? I'm willing to submit patches if necessary, but I'm not at all familiar with GHC internals, so would need some guidance. I understand that comprehensions tend not to be used much in idiomatic Haskell, but I find them to be useful for implementing DSLs, so would really like to see this be supported. For example, a matrix could be written in a familiar notation:
[ i + 2*j | i <- rows, j <- cols ]
which is a little more readable (to those not familiar with Haskell) than
(\i j -> i + 2*j) <$> row <*> cols
or
do { i <- rows; j <- cols; return (i + 2*j) }
[1] https://ghc.haskell.org/trac/ghc/wiki/Status/GHC-8.0.1#LandedinHEAD [2] https://ghc.haskell.org/trac/ghc/wiki/GeneralizedMonadComprehensions#Applica... -- David A Roberts https://davidar.io

Hi, Am Montag, den 12.10.2015, 08:09 +0000 schrieb David A Roberts:
I understand that comprehensions tend not to be used much in idiomatic Haskell,
quite contrary! I use them extensively in real-world-projects, and I claim to write idomatic code :-) Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

I certainly second that! Manuel
Joachim Breitner
: Hi,
Am Montag, den 12.10.2015, 08:09 +0000 schrieb David A Roberts:
I understand that comprehensions tend not to be used much in idiomatic Haskell,
quite contrary! I use them extensively in real-world-projects, and I claim to write idomatic code :-)
Greetings, Joachim
-- Joachim “nomeata” Breitner mail@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Sounds reasonable to me. Do-notation and comprehension notation are really just syntactic sugar for the same thing. Simon From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of David A Roberts Sent: 12 October 2015 09:10 To: ghc-devs@haskell.org Subject: Applicative Comprehensions Hi, I raised this question on #haskell, and was advised that this was probably the best place to discuss. I see that Applicative Do is scheduled for GHC 8.0 [1], and was hoping that this might also enable support for Applicative Comprehensions [2]. Is this likely to be the case? If not, would it be difficult to extend the support for Applicative Do to also handle comprehensions? I'm willing to submit patches if necessary, but I'm not at all familiar with GHC internals, so would need some guidance. I understand that comprehensions tend not to be used much in idiomatic Haskell, but I find them to be useful for implementing DSLs, so would really like to see this be supported. For example, a matrix could be written in a familiar notation:
[ i + 2*j | i <- rows, j <- cols ] which is a little more readable (to those not familiar with Haskell) than (\i j -> i + 2*j) <$> row <*> cols or
do { i <- rows; j <- cols; return (i + 2*j) } [1] https://ghc.haskell.org/trac/ghc/wiki/Status/GHC-8.0.1#LandedinHEAD [2] https://ghc.haskell.org/trac/ghc/wiki/GeneralizedMonadComprehensions#Applica... -- David A Roberts https://davidar.iohttps://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fdavidar.io&data=01%7c01%7csimonpj%40064d.mgd.microsoft.com%7c1b9d9b3d0c48462fe9b708d2d2dc85b7%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=TVwAqgK%2bfp8IxsiPnkBDQ6nRGZmCDB4oJNiGX%2f%2f9N8U%3d

I like this idea because having the pure function call at the beginning (rather than at the end, as with do-notation) is more consistent with the original <$>,<*>-notation. It only slightly bothers me that the bracket notation in this form has nothing to do with lists, so that may be a bit confusing. But this is already true for monad comprehensions. It might make more sense to reuse the parallel list comprehension syntax (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/syntax-extns...), as applicatives are "parallel". So, [ i + 2*j | i <- rows | j <- cols ]. On 10/12/2015 11:09 AM, David A Roberts wrote:
Hi,
I raised this question on #haskell, and was advised that this was probably the best place to discuss.
I see that Applicative Do is scheduled for GHC 8.0 [1], and was hoping that this might also enable support for Applicative Comprehensions [2]. Is this likely to be the case? If not, would it be difficult to extend the support for Applicative Do to also handle comprehensions? I'm willing to submit patches if necessary, but I'm not at all familiar with GHC internals, so would need some guidance.
I understand that comprehensions tend not to be used much in idiomatic Haskell, but I find them to be useful for implementing DSLs, so would really like to see this be supported. For example, a matrix could be written in a familiar notation:
[ i + 2*j | i <- rows, j <- cols ]
which is a little more readable (to those not familiar with Haskell) than
(\i j -> i + 2*j) <$> row <*> cols
or
do { i <- rows; j <- cols; return (i + 2*j) }
[1] https://ghc.haskell.org/trac/ghc/wiki/Status/GHC-8.0.1#LandedinHEAD [2] https://ghc.haskell.org/trac/ghc/wiki/GeneralizedMonadComprehensions#Applica...
-- David A Roberts https://davidar.io
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Paralell comprehension syntax will be confusing. If user have both MonadComprehensions and ApplicativeDo enabled, it makes total sense to desugar monad comprehensions into Applicative expression when it’s possible, and into Monadic otherwise. I’m actually a bit surprised if it’s not already a case. - Oleg
On 12 Oct 2015, at 10:14, Roman Cheplyaka
wrote: I like this idea because having the pure function call at the beginning (rather than at the end, as with do-notation) is more consistent with the original <$>,<*>-notation.
It only slightly bothers me that the bracket notation in this form has nothing to do with lists, so that may be a bit confusing. But this is already true for monad comprehensions.
It might make more sense to reuse the parallel list comprehension syntax (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/syntax-extns...), as applicatives are "parallel". So, [ i + 2*j | i <- rows | j <- cols ].
On 10/12/2015 11:09 AM, David A Roberts wrote:
Hi,
I raised this question on #haskell, and was advised that this was probably the best place to discuss.
I see that Applicative Do is scheduled for GHC 8.0 [1], and was hoping that this might also enable support for Applicative Comprehensions [2]. Is this likely to be the case? If not, would it be difficult to extend the support for Applicative Do to also handle comprehensions? I'm willing to submit patches if necessary, but I'm not at all familiar with GHC internals, so would need some guidance.
I understand that comprehensions tend not to be used much in idiomatic Haskell, but I find them to be useful for implementing DSLs, so would really like to see this be supported. For example, a matrix could be written in a familiar notation:
[ i + 2*j | i <- rows, j <- cols ]
which is a little more readable (to those not familiar with Haskell) than
(\i j -> i + 2*j) <$> row <*> cols
or
do { i <- rows; j <- cols; return (i + 2*j) }
[1] https://ghc.haskell.org/trac/ghc/wiki/Status/GHC-8.0.1#LandedinHEAD [2] https://ghc.haskell.org/trac/ghc/wiki/GeneralizedMonadComprehensions#Applica...
-- David A Roberts https://davidar.io
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

On 12/10/2015 09:09, David A Roberts wrote:
Hi,
I raised this question on #haskell, and was advised that this was probably the best place to discuss.
I see that Applicative Do is scheduled for GHC 8.0 [1], and was hoping that this might also enable support for Applicative Comprehensions [2]. Is this likely to be the case? If not, would it be difficult to extend the support for Applicative Do to also handle comprehensions? I'm willing to submit patches if necessary, but I'm not at all familiar with GHC internals, so would need some guidance.
I understand that comprehensions tend not to be used much in idiomatic Haskell, but I find them to be useful for implementing DSLs, so would really like to see this be supported. For example, a matrix could be written in a familiar notation:
[ i + 2*j | i <- rows, j <- cols ]
which is a little more readable (to those not familiar with Haskell) than
(\i j -> i + 2*j) <$> row <*> cols
or
do { i <- rows; j <- cols; return (i + 2*j) }
Good idea - it's not currently implemented, but it wouldn't be hard to do. Want to make a feature request and CC me on it? Sounds like something that might just fit into my train journey to work :) Cheers, Simon
participants (7)
-
David A Roberts
-
Joachim Breitner
-
Manuel M T Chakravarty
-
Oleg Grenrus
-
Roman Cheplyaka
-
Simon Marlow
-
Simon Peyton Jones