The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Mark Elston (133) [Avatar] Offline
I had trouble following the explanation of listing 14.13. Haskell syntax is pretty clean but I still found this listing a bit harder to follow than most of the others. Part of the problem was I wasn't sure what direction you were heading when you presented the listing so following the function composition was difficult. Add to that there were some typos in the explanation and I got confused. So I suggest the something along the following lines for the points below the listing:

1) (This is OK as is except it has nothing to do with making copies. It is just getting the number of copies to make)
2) Map *over* l1 and return lists of nToAdd copies of each element. This results in a 'list of lists'
3) Reduce the 'list of lists' to a single list of elements
4) (OK as it is)

I think this is a bit clearer than the original. It was the way I finally figured out what you were doing. In addition, I'm not sure you spent a whole lot of time on function composition so the effect of
map ((take nToAdd) . repeat) l1
may not be obvious to all. I certainly had to stare at it a while before I figured out what this did.