[Haskell-beginners] Correction needed in Real World Haskell, chapter 24 (Concurrency and Parallelism)?

Obscaenvs obscaenvs at gmail.com
Tue Aug 7 12:22:10 CEST 2012


At 
http://book.realworldhaskell.org/read/concurrent-and-multicore-programming.html#id675459 
, just after the code for `sillySort`, it says

<quote>
"In this mistaken example, we evaluate each sorted sublist to WHNF. 
Since the outermost constructor in each case is just a single list 
constructor, we are in fact only forcing the evaluation of the first 
element of each sorted sublist! Every other element of each list remains 
unevaluated."
</quote>

My ruminations on the subject ended up in the following analysis, which 
is quite contrary to that of the authors':
In the general case of the type inside the list being just an instance 
of Ord, it is *not* the case that the first element is necessarily 
evaluated; it is evaluated just enough (along with the elements of the 
*rest* of the lists greater and lesser) to enable < and >= to do their 
job inside the list comprehensions. Now, if these elements are Int:s or 
Integer:s then certainly, yes, the first element *is* evaluated, but so 
is the rest of the elements of the lists greater and lesser.

So, greater and lesser are not only reduced to WHNF, but to NF in the 
case of sillySort working on [Int] or [Integer].

Am I mistaken in my analysis? If so, where?

/Fredrik

-- 
haskellBlog: http://www.monoid.se/categories/haskell/




More information about the Beginners mailing list