
On 22/10/06, Chad Scherrer
Hi,
I had posted this question a while back, but I think it was in the middle of another discussion, and I never did get a reply. Do we really need both Control.Parallel.Strategies.rnf and deepSeq? Should we not always have
x `deepSeq` y == rnf x `seq` y ?
Maybe there's a distinction I'm missing, but it seems to me they're basically the same.
I agree, they are the same. The Strategies library also gives much more general operations for working with strictness and parallelisation. That library seems to need more love, I think it's a great idea, but it doesn't really get noticed all that much. The Hierarchical libraries documentation for it is a little lacking -- it doesn't even provide a reference or link to the paper, and many of the combinators, as well as the general idea of how to use it are undocumented from there. It also spuriously contains an Assoc datatype, which if I recall correctly, was an example from the paper, but doesn't really belong in the library as far as I can tell. It would also be really nice to see the list of instances for the NFData class expanded to include other datatypes in the libraries, possibly also with compiler support for deriving, since it's mostly boilerplate. Speaking of boilerplate and the scrapping thereof, Data.Generics could theoretically also be used to write a relatively generic rnf/deepSeq, but in my attempts, it seems to be much much slower than using a specific normal form class. Here's my code from quite a while back. As I recall, it's semantically correct, but ran about an order of magnitude slower. There might be a much better way to do it, I don't really know Data.Generics all that well. rnf :: (Data a) => a -> () rnf x = everything (\x y -> x `seq` y) (\x -> x `seq` ()) x deepSeq x y = rnf x `seq` y f $!! x = rnf x `seq` f x - Cale

Hello Cale, Monday, October 23, 2006, 7:19:14 AM, you wrote:
Speaking of boilerplate and the scrapping thereof, Data.Generics could theoretically also be used to write a relatively generic rnf/deepSeq, but in my attempts, it seems to be much much slower than using a specific normal form class. Here's my code from quite a while back. As I recall, it's semantically correct, but ran about an order of magnitude slower. There might be a much better way to do it, I don't really know Data.Generics all that well.
by no means it's surprising - syb library works slower than hand-written or compile-time generated code because it implements _run-time_ polymorphism - data types are tested at run-time and then coerced to their actual types. there is also syb4 approach by Oleg where type classes used for polymorphism - it should have average speed, in theory -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Cale Gibbard wrote:
On 22/10/06, Chad Scherrer
wrote: Hi,
I had posted this question a while back, but I think it was in the middle of another discussion, and I never did get a reply. Do we really need both Control.Parallel.Strategies.rnf and deepSeq? Should we not always have
x `deepSeq` y == rnf x `seq` y ?
Maybe there's a distinction I'm missing, but it seems to me they're basically the same.
I agree, they are the same. The Strategies library also gives much more general operations for working with strictness and parallelisation. That library seems to need more love, I think it's a great idea, but it doesn't really get noticed all that much. The Hierarchical libraries documentation for it is a little lacking -- it doesn't even provide a reference or link to the paper, and many of the combinators, as well as the general idea of how to use it are undocumented from there. It also spuriously contains an Assoc datatype, which if I recall correctly, was an example from the paper, but doesn't really belong in the library as far as I can tell. It would also be really nice to see the list of instances for the NFData class expanded to include other datatypes in the libraries, possibly also with compiler support for deriving, since it's mostly boilerplate.
I wanted to use the Strategies library and didn't understand much of it, so I sat down and documented it. The darcs version, http://darcs.haskell.org/packages/base/Control/Parallel/Strategies.hs has my changes. If noone objects, I could do some more clean-up, including: - Add NFData instances for common data types, such as - Maybe - Either - Data.Map.Map - Data.Set.Set - Data.Tree.Tree - All Data.Int and Data.Word types - Deprecate sSeq and sPar, as the code comments say that you should use demanding and sparking instead. - Deprecate these defintions, which seem to be examples or Lolita-specific: - Assoc - fstPairFstList - force - sforce If anyone has objections or further suggestions, let me know. /Björn

Björn Bringert wrote:
Cale Gibbard wrote:
On 22/10/06, Chad Scherrer
wrote: Hi,
I had posted this question a while back, but I think it was in the middle of another discussion, and I never did get a reply. Do we really need both Control.Parallel.Strategies.rnf and deepSeq? Should we not always have
x `deepSeq` y == rnf x `seq` y ?
Maybe there's a distinction I'm missing, but it seems to me they're basically the same.
I agree, they are the same. The Strategies library also gives much more general operations for working with strictness and parallelisation. That library seems to need more love, I think it's a great idea, but it doesn't really get noticed all that much. The Hierarchical libraries documentation for it is a little lacking -- it doesn't even provide a reference or link to the paper, and many of the combinators, as well as the general idea of how to use it are undocumented from there. It also spuriously contains an Assoc datatype, which if I recall correctly, was an example from the paper, but doesn't really belong in the library as far as I can tell. It would also be really nice to see the list of instances for the NFData class expanded to include other datatypes in the libraries, possibly also with compiler support for deriving, since it's mostly boilerplate.
I wanted to use the Strategies library and didn't understand much of it, so I sat down and documented it. The darcs version, http://darcs.haskell.org/packages/base/Control/Parallel/Strategies.hs has my changes.
If noone objects, I could do some more clean-up, including:
- Add NFData instances for common data types, such as - Maybe - Either - Data.Map.Map - Data.Set.Set - Data.Tree.Tree - All Data.Int and Data.Word types
- Deprecate sSeq and sPar, as the code comments say that you should use demanding and sparking instead.
- Deprecate these defintions, which seem to be examples or Lolita-specific: - Assoc - fstPairFstList - force - sforce
If anyone has objections or further suggestions, let me know.
Looks good to me. I didn't really look closely at this code before enabling it, except to check that it compiled and appeared to work with a couple of the old Parallel Haskell benchmarks in nofib/par. Cheers, Simon

On Mon, Nov 13, 2006 at 02:47:20PM +0100, Björn Bringert wrote:
I wanted to use the Strategies library and didn't understand much of it, so I sat down and documented it. The darcs version, http://darcs.haskell.org/packages/base/Control/Parallel/Strategies.hs has my changes.
Perhaps it would make sense to move all the NFData material to a new module called, say, Control.NormalForm, and maybe add a deepSeq function there. Control.Parallel.Strategies is a somewhat surprising place to find normal form functions, and most of the people who are using them aren't thinking about parallelism.

Ross Paterson
On Mon, Nov 13, 2006 at 02:47:20PM +0100, Björn Bringert wrote:
I wanted to use the Strategies library and didn't understand much of it, so I sat down and documented it. The darcs version, http://darcs.haskell.org/packages/base/Control/Parallel/Strategies.hs has my changes.
Perhaps it would make sense to move all the NFData material to a new module called, say, Control.NormalForm, and maybe add a deepSeq function there. Control.Parallel.Strategies is a somewhat surprising place to find normal form functions, and most of the people who are using them aren't thinking about parallelism.
Agreed. [ Bikeshed time: Control.Evaluation.Strategies anyone? ] Regards, Malcolm

On 24/11/06, Malcolm Wallace
Agreed. [ Bikeshed time: Control.Evaluation.Strategies anyone? ]
I agree Control.Evaluation.Strategies makes more sense. I think people have had a hard time finding the library due to the "Parallel" in the path.

On Fri, Nov 24, 2006 at 02:53:45PM +0000, Malcolm Wallace wrote:
Ross Paterson
wrote: Perhaps it would make sense to move all the NFData material to a new module called, say, Control.NormalForm, and maybe add a deepSeq function there. Control.Parallel.Strategies is a somewhat surprising place to find normal form functions, and most of the people who are using them aren't thinking about parallelism.
Agreed. [ Bikeshed time: Control.Evaluation.Strategies anyone? ]
The suggestion is a module containing just class NFData, instances for Prelude types, and perhaps deepSeq :: NFData a => a -> b -> b deepSeq x y = rnf x `seq` y Shouldn't it have something like NF in the name?

On 24/11/06, Ross Paterson
On Fri, Nov 24, 2006 at 02:53:45PM +0000, Malcolm Wallace wrote:
Ross Paterson
wrote: Perhaps it would make sense to move all the NFData material to a new module called, say, Control.NormalForm, and maybe add a deepSeq function there. Control.Parallel.Strategies is a somewhat surprising place to find normal form functions, and most of the people who are using them aren't thinking about parallelism.
Agreed. [ Bikeshed time: Control.Evaluation.Strategies anyone? ]
The suggestion is a module containing just class NFData, instances for Prelude types, and perhaps
deepSeq :: NFData a => a -> b -> b deepSeq x y = rnf x `seq` y
Shouldn't it have something like NF in the name?
Well, it shouldn't just have that. There's more in Control.Parallel.Strategies which would be useful in general (e.g. seqList). Perhaps the hierarchy should flip into: Control.Strategies.Sequential Control.Strategies.Parallel Control.Strategies could reexport both. Another thing is that the library is presently under-documented as far as Haddock is concerned (what's the difference between >| and >||). It'd be nice if at least a short comment was added to each function.

Ross Paterson
Perhaps it would make sense to move all the NFData material to a new module called, say, Control.NormalForm,
Agreed. [ Bikeshed time: Control.Evaluation.Strategies anyone? ]
The suggestion is a module containing just class NFData, instances for Prelude types, and perhaps
deepSeq :: NFData a => a -> b -> b deepSeq x y = rnf x `seq` y
Shouldn't it have something like NF in the name?
Well, "NormalForm" perhaps, cryptic abbreviations like NF, no. But that aside, I hadn't realised you were proposing to move so little. Would it not be useful to have a lot more of the evaluation strategy stuff widely available, even to sequential programs? Regards, Malcolm
participants (6)
-
Björn Bringert
-
Bulat Ziganshin
-
Cale Gibbard
-
Malcolm Wallace
-
Ross Paterson
-
Simon Marlow