Strictifying monadic values, take 3

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 (HTML-rendered version of the text below see [1]) Strictifying Monadic values =========================== Half a year ago, Johan Tibell proposed adding a strict equivalent to fmap [2]. This discussion got lost in details, it was reopened, it ended in bikeshedding again. This is a third attempt to get this through, with individual options and no alternatives proposed, compiled from the two more popular responses in the other threads. Please do not propose alternative implementations here, we've been through this twice already. Vote ±1 on each point to show (dis)agreement. I think this functionality should be in the standard libraries in one way or another, regardless of how it's named in the end. 1. Add a strict version of <$>, named <$!>. ```haskell infixl 4 <$!> (<$!>) :: Monad m => (a -> b) -> m a -> m b f <$!> m = do x <- m return $! f x ``` This is closely related to fmap in terms of functionality, but requires a Monad constraint. This would allow defining ```haskell seqM m = id <$!> m ``` if such a function is needed. 2. Add a seqM function that evaluates the "contents" of a monadic action to WHNF. ```haskell seqM :: Monad m => m a -> m a seqM m = do x <- m return $! x ``` This is less close to fmap, but allows building other strict operations (locally and as needed) based on it easier, for example ```haskell f <$!> x = seqM ( f <$> x) mf <*!> mx = seqM (mf <*> mx) mf <*! mx = seqM (mf <* mx) mf *!> mx = seqM (mf *> mx) ``` If these operators then turn out to be used (and locally reinvented) very often by different people, reconsider adding them as well. A voting period of two weeks (until 10-05-2014) should be sufficient to allow everyone to join in. Greetings, David Links: [1]: https://github.com/quchen/articles/blob/master/seqm_proposal.md [2]: http://www.haskell.org/pipermail/libraries/2013-November/021728.html -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJTXAWmAAoJELrQsaT5WQUs9GgH/3Vr2nDUDyX7pU24Vs0Dfq6e 43xcgY5ZBXCk/v/L6b14DA2br+jc32GkAnwkoWvJYQDNc6E6QwdPUnyaFpNPthA3 7NDcuGukJPzpkkA/YCVqq4Yu6jIwjcVm/xMQaRmASWMnlJxEypFuuMirWVUgg+ED Zl9x2VUoFUoRq6TpE1TGcOS0eoevqvu7LDdTJkGEC7wNxZOD4a2hjyiv90e2LmYL mP0pPKVj2NfSjIfDa/q+ONIHN+hrQqriku9OJSGU8UVxOfAvi86W42xsFV6fNdVE OKc/TTKM4V23G7qw3Dpz1EGnXqqLdYlv1ck2EF05tmSOjJ6Bx2lAUBypRyjX6IA= =+wNo -----END PGP SIGNATURE-----

+1 for me on (<$!>). I have inlined it in multiple packages. I'm neutral on the other combinator. -Edward On Sat, Apr 26, 2014 at 3:14 PM, David Luposchainsky < dluposchainsky@googlemail.com> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
(HTML-rendered version of the text below see [1])
Strictifying Monadic values ===========================
Half a year ago, Johan Tibell proposed adding a strict equivalent to fmap [2]. This discussion got lost in details, it was reopened, it ended in bikeshedding again. This is a third attempt to get this through, with individual options and no alternatives proposed, compiled from the two more popular responses in the other threads.
Please do not propose alternative implementations here, we've been through this twice already. Vote ±1 on each point to show (dis)agreement. I think this functionality should be in the standard libraries in one way or another, regardless of how it's named in the end.
1. Add a strict version of <$>, named <$!>.
```haskell infixl 4 <$!>
(<$!>) :: Monad m => (a -> b) -> m a -> m b f <$!> m = do x <- m return $! f x ```
This is closely related to fmap in terms of functionality, but requires a Monad constraint.
This would allow defining
```haskell seqM m = id <$!> m ```
if such a function is needed.
2. Add a seqM function that evaluates the "contents" of a monadic action to WHNF.
```haskell seqM :: Monad m => m a -> m a seqM m = do x <- m return $! x ```
This is less close to fmap, but allows building other strict operations (locally and as needed) based on it easier, for example
```haskell f <$!> x = seqM ( f <$> x) mf <*!> mx = seqM (mf <*> mx) mf <*! mx = seqM (mf <* mx) mf *!> mx = seqM (mf *> mx) ```
If these operators then turn out to be used (and locally reinvented) very often by different people, reconsider adding them as well.
A voting period of two weeks (until 10-05-2014) should be sufficient to allow everyone to join in.
Greetings, David
Links: [1]: https://github.com/quchen/articles/blob/master/seqm_proposal.md [2]: http://www.haskell.org/pipermail/libraries/2013-November/021728.html -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJTXAWmAAoJELrQsaT5WQUs9GgH/3Vr2nDUDyX7pU24Vs0Dfq6e 43xcgY5ZBXCk/v/L6b14DA2br+jc32GkAnwkoWvJYQDNc6E6QwdPUnyaFpNPthA3 7NDcuGukJPzpkkA/YCVqq4Yu6jIwjcVm/xMQaRmASWMnlJxEypFuuMirWVUgg+ED Zl9x2VUoFUoRq6TpE1TGcOS0eoevqvu7LDdTJkGEC7wNxZOD4a2hjyiv90e2LmYL mP0pPKVj2NfSjIfDa/q+ONIHN+hrQqriku9OJSGU8UVxOfAvi86W42xsFV6fNdVE OKc/TTKM4V23G7qw3Dpz1EGnXqqLdYlv1ck2EF05tmSOjJ6Bx2lAUBypRyjX6IA= =+wNo -----END PGP SIGNATURE----- _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

+1 on <$!>
+0 on the other proposal, which will requires a local definition to be
useful.
On Apr 26, 2014 10:33 PM, "Edward Kmett"
+1 for me on (<$!>). I have inlined it in multiple packages.
I'm neutral on the other combinator.
-Edward
On Sat, Apr 26, 2014 at 3:14 PM, David Luposchainsky < dluposchainsky@googlemail.com> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
(HTML-rendered version of the text below see [1])
Strictifying Monadic values ===========================
Half a year ago, Johan Tibell proposed adding a strict equivalent to fmap [2]. This discussion got lost in details, it was reopened, it ended in bikeshedding again. This is a third attempt to get this through, with individual options and no alternatives proposed, compiled from the two more popular responses in the other threads.
Please do not propose alternative implementations here, we've been through this twice already. Vote ±1 on each point to show (dis)agreement. I think this functionality should be in the standard libraries in one way or another, regardless of how it's named in the end.
1. Add a strict version of <$>, named <$!>.
```haskell infixl 4 <$!>
(<$!>) :: Monad m => (a -> b) -> m a -> m b f <$!> m = do x <- m return $! f x ```
This is closely related to fmap in terms of functionality, but requires a Monad constraint.
This would allow defining
```haskell seqM m = id <$!> m ```
if such a function is needed.
2. Add a seqM function that evaluates the "contents" of a monadic action to WHNF.
```haskell seqM :: Monad m => m a -> m a seqM m = do x <- m return $! x ```
This is less close to fmap, but allows building other strict operations (locally and as needed) based on it easier, for example
```haskell f <$!> x = seqM ( f <$> x) mf <*!> mx = seqM (mf <*> mx) mf <*! mx = seqM (mf <* mx) mf *!> mx = seqM (mf *> mx) ```
If these operators then turn out to be used (and locally reinvented) very often by different people, reconsider adding them as well.
A voting period of two weeks (until 10-05-2014) should be sufficient to allow everyone to join in.
Greetings, David
Links: [1]: https://github.com/quchen/articles/blob/master/seqm_proposal.md [2]: http://www.haskell.org/pipermail/libraries/2013-November/021728.html -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJTXAWmAAoJELrQsaT5WQUs9GgH/3Vr2nDUDyX7pU24Vs0Dfq6e 43xcgY5ZBXCk/v/L6b14DA2br+jc32GkAnwkoWvJYQDNc6E6QwdPUnyaFpNPthA3 7NDcuGukJPzpkkA/YCVqq4Yu6jIwjcVm/xMQaRmASWMnlJxEypFuuMirWVUgg+ED Zl9x2VUoFUoRq6TpE1TGcOS0eoevqvu7LDdTJkGEC7wNxZOD4a2hjyiv90e2LmYL mP0pPKVj2NfSjIfDa/q+ONIHN+hrQqriku9OJSGU8UVxOfAvi86W42xsFV6fNdVE OKc/TTKM4V23G7qw3Dpz1EGnXqqLdYlv1ck2EF05tmSOjJ6Bx2lAUBypRyjX6IA= =+wNo -----END PGP SIGNATURE----- _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

+1 on <$!> Neutral on the other. John L. On Apr 26, 2014 12:14 PM, "David Luposchainsky" < dluposchainsky@googlemail.com> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
(HTML-rendered version of the text below see [1])
Strictifying Monadic values ===========================
Half a year ago, Johan Tibell proposed adding a strict equivalent to fmap [2]. This discussion got lost in details, it was reopened, it ended in bikeshedding again. This is a third attempt to get this through, with individual options and no alternatives proposed, compiled from the two more popular responses in the other threads.
Please do not propose alternative implementations here, we've been through this twice already. Vote ±1 on each point to show (dis)agreement. I think this functionality should be in the standard libraries in one way or another, regardless of how it's named in the end.
1. Add a strict version of <$>, named <$!>.
```haskell infixl 4 <$!>
(<$!>) :: Monad m => (a -> b) -> m a -> m b f <$!> m = do x <- m return $! f x ```
This is closely related to fmap in terms of functionality, but requires a Monad constraint.
This would allow defining
```haskell seqM m = id <$!> m ```
if such a function is needed.
2. Add a seqM function that evaluates the "contents" of a monadic action to WHNF.
```haskell seqM :: Monad m => m a -> m a seqM m = do x <- m return $! x ```
This is less close to fmap, but allows building other strict operations (locally and as needed) based on it easier, for example
```haskell f <$!> x = seqM ( f <$> x) mf <*!> mx = seqM (mf <*> mx) mf <*! mx = seqM (mf <* mx) mf *!> mx = seqM (mf *> mx) ```
If these operators then turn out to be used (and locally reinvented) very often by different people, reconsider adding them as well.
A voting period of two weeks (until 10-05-2014) should be sufficient to allow everyone to join in.
Greetings, David
Links: [1]: https://github.com/quchen/articles/blob/master/seqm_proposal.md [2]: http://www.haskell.org/pipermail/libraries/2013-November/021728.html -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJTXAWmAAoJELrQsaT5WQUs9GgH/3Vr2nDUDyX7pU24Vs0Dfq6e 43xcgY5ZBXCk/v/L6b14DA2br+jc32GkAnwkoWvJYQDNc6E6QwdPUnyaFpNPthA3 7NDcuGukJPzpkkA/YCVqq4Yu6jIwjcVm/xMQaRmASWMnlJxEypFuuMirWVUgg+ED Zl9x2VUoFUoRq6TpE1TGcOS0eoevqvu7LDdTJkGEC7wNxZOD4a2hjyiv90e2LmYL mP0pPKVj2NfSjIfDa/q+ONIHN+hrQqriku9OJSGU8UVxOfAvi86W42xsFV6fNdVE OKc/TTKM4V23G7qw3Dpz1EGnXqqLdYlv1ck2EF05tmSOjJ6Bx2lAUBypRyjX6IA= =+wNo -----END PGP SIGNATURE----- _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hey everyone, the discussion period is over, and it seems all (five or so) voted in favour of <$!>. Since I'm the only one who seems to like seqM, I did not include it in the ticket. https://ghc.haskell.org/trac/ghc/ticket/9099 Greetings, David/quchen PS: Let's open a new thread about whether this should be in Data.Functor or Control.Monad and we'll have it in by the end of the year! ;-) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJTcMKRAAoJELrQsaT5WQUspWcH/i7up48frmvBUpKWhd7P4ODe e+FzY4bWvYVLRu41X8ZTraPSL7WxlKToNy7EDHyqghBoL9ojYlaDLWCZruNLLeIF Vp2cZziQxFd5IqFWepwiYVLV44rgeNfSh1eLOysGCgyHvYP9NslGDfjVgnz3OraF FZ/FzA+5EaKkUCT6dSXMH18uUPI4WUVmw4vfzgDuEsmLf3RGGl+FZy6+FbD6Ylvd l5W8F7/WuStv8irJSZ6UoUBvuJPOqgRPWzK5R1qOheBAe38Xpl7vhwtYfvytxXeR u9NPcrwOGhSRHPOw+8Ub0IsUygSHYBr9yCa1pvc1KcztBW3TCleGeozsh5+kN40= =5ZdB -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 26/04/14 21:14, David Luposchainsky wrote:
(<$!>) :: Monad m => (a -> b) -> m a -> m b +1.
Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNeNCwACgkQRtClrXBQc7UeXAD/d3xgIlQ2eLwncwxEjYJIHOSi B699UB8/t6RA6/Nf/QwA/iUdmW5mT1tEv4Suti39Bf/ce08JYHUzpGlGUvPRIjpw =5v8m -----END PGP SIGNATURE-----
participants (5)
-
Alexander Berntsen
-
David Luposchainsky
-
Edward Kmett
-
Johan Tibell
-
John Lato