Proposal: Add an analogue of $! to deepseq

I propose we add a operator - tentatively labelled $!! (and which Hayoo reports isn't currently exported by a Hackage package) - as a deepseq analogue $! to the deepseq library: ($!!) :: (NFData a) => (a -> b) ->a -> b f $!! x = x `deepseq` f x infixr 0 $!! As a sub-proposal, I also propose that we add a "force" function (the name of which also seems to be unused) to make it easier to test forcing of values: force :: (NFData a) => a -> a force x = x `deepseq` x Discussion time: 2 weeks -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

On Friday 01 July 2011, 09:55:40, Ivan Lazar Miljenovic wrote:
I propose we add a operator - tentatively labelled $!! (and which Hayoo reports isn't currently exported by a Hackage package) - as a deepseq analogue $! to the deepseq library:
($!!) :: (NFData a) => (a -> b) ->a -> b f $!! x = x `deepseq` f x
infixr 0 $!!
I think that would be useful.
As a sub-proposal, I also propose that we add a "force" function (the name of which also seems to be unused) to make it easier to test forcing of values:
force :: (NFData a) => a -> a force x = x `deepseq` x
Could also be useful.
Discussion time: 2 weeks
+1

($!!) :: (NFData a) => (a -> b) ->a -> b f $!! x = x `deepseq` f x
Could be useful.
force :: (NFData a) => a -> a force x = x `deepseq` x
I'm not convinced this forces x at the point where you want it to. For instance, foldlw f a (x:xs) = foldlw f (force (f a x)) xs would not give you the foldl' you might be looking for - indeed it is identical to the space-leaking foldl, apart from the extra class constraint. Regards, Malcolm

infixr 0 $!!
+1 Incedentally, Curry already has it: http://www.informatik.uni-kiel.de/~pakcs/lib/CDOC/Prelude.html#$!!
force :: (NFData a) => a -> a force x = x `deepseq` x
Might be a bit confusing as it forces NF only when HNF is forced (which might be later than expected by people not too familiar with laziness). Sebastian

At 5:55 PM +1000 7/1/11, Ivan Lazar Miljenovic wrote:
I propose we add a operator - tentatively labelled $!! (and which Hayoo reports isn't currently exported by a Hackage package) - as a deepseq analogue $! to the deepseq library:
($!!) :: (NFData a) => (a -> b) ->a -> b f $!! x = x `deepseq` f x
infixr 0 $!!
+1 Note that I included the ($!!) operator in my original DeepSeq module (http://haskell.org/pipermail/haskell/2001-August/001586.html). Dean

On 01/07/2011 08:55, Ivan Lazar Miljenovic wrote:
I propose we add a operator - tentatively labelled $!! (and which Hayoo reports isn't currently exported by a Hackage package) - as a deepseq analogue $! to the deepseq library:
($!!) :: (NFData a) => (a -> b) ->a -> b f $!! x = x `deepseq` f x
infixr 0 $!!
+1
As a sub-proposal, I also propose that we add a "force" function (the name of which also seems to be unused) to make it easier to test forcing of values:
force :: (NFData a) => a -> a force x = x `deepseq` x
Yes, this is what I called "deep" in my parallelism tutorial [1], but "force" is a better name. If it goes in, I'll update the tutorial. Cheers, Simon [1] http://community.haskell.org/~simonmar/par-tutorial.pdf

It's been two weeks since I raised this, and as such discussion time
is over. For the complete discussion, please see
http://www.haskell.org/pipermail/libraries/2011-July/016540.html
In total, there were five respondees.
On 1 July 2011 17:55, Ivan Lazar Miljenovic
I propose we add a operator - tentatively labelled $!! (and which Hayoo reports isn't currently exported by a Hackage package) - as a deepseq analogue $! to the deepseq library:
($!!) :: (NFData a) => (a -> b) ->a -> b f $!! x = x `deepseq` f x
infixr 0 $!!
All respondees agreed with this proposal; as such it passes.
As a sub-proposal, I also propose that we add a "force" function (the name of which also seems to be unused) to make it easier to test forcing of values:
force :: (NFData a) => a -> a force x = x `deepseq` x
* Two people agreed with this proposal. * Two people indicated that it may produce confusing results (one of which at least can be seen as a vote against this proposal), * The fifth respondee didn't mention it. As such, including myself in the tally, I would consider that this proposal passes, but that we should add sufficient documentation to cover Malcolm's and Sebastian's concerns (specifically that using force inside a left-fold would actually be more analogous to foldl than foldl', and that a reminder should be made that this will evaluate the value to NF rather than HNF, which is indeed the point). I will now go and create a ticket on the GHC Trac. @Simon: as the maintainer of deepseq, would you prefer I create a patch with these changes, or will you do so yourself? -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

The ticket for this is http://hackage.haskell.org/trac/ghc/ticket/5323
On 15 July 2011 08:49, Ivan Lazar Miljenovic
It's been two weeks since I raised this, and as such discussion time is over. For the complete discussion, please see http://www.haskell.org/pipermail/libraries/2011-July/016540.html
In total, there were five respondees.
On 1 July 2011 17:55, Ivan Lazar Miljenovic
wrote: I propose we add a operator - tentatively labelled $!! (and which Hayoo reports isn't currently exported by a Hackage package) - as a deepseq analogue $! to the deepseq library:
($!!) :: (NFData a) => (a -> b) ->a -> b f $!! x = x `deepseq` f x
infixr 0 $!!
All respondees agreed with this proposal; as such it passes.
As a sub-proposal, I also propose that we add a "force" function (the name of which also seems to be unused) to make it easier to test forcing of values:
force :: (NFData a) => a -> a force x = x `deepseq` x
* Two people agreed with this proposal.
* Two people indicated that it may produce confusing results (one of which at least can be seen as a vote against this proposal),
* The fifth respondee didn't mention it.
As such, including myself in the tally, I would consider that this proposal passes, but that we should add sufficient documentation to cover Malcolm's and Sebastian's concerns (specifically that using force inside a left-fold would actually be more analogous to foldl than foldl', and that a reminder should be made that this will evaluate the value to NF rather than HNF, which is indeed the point).
I will now go and create a ticket on the GHC Trac.
@Simon: as the maintainer of deepseq, would you prefer I create a patch with these changes, or will you do so yourself?
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com
participants (6)
-
Daniel Fischer
-
Dean Herington
-
Ivan Lazar Miljenovic
-
Malcolm Wallace
-
Sebastian Fischer
-
Simon Marlow