realworldocaml / examples

All the examples in Real World OCaml
The Unlicense
376 stars 81 forks source link

Change drop_value to be tail-recursive. #12

Closed ghost closed 10 years ago

ghost commented 10 years ago

drop_value in lists_and_patterns seems, for no reason, to not be tail recursive. I found that confusing. If there is a good reason, should it not be discussed a bit in the book?

ghost commented 10 years ago

Sorry, it looks like you cover this optimisation later on the chapter. The definition just looked weird to a non-beginner, maybe the drop_value definition as presented is more natural to beginners in your experience, I've no idea.

samoht commented 10 years ago

FWI, the function you are proposing is not tail recursive.

ghost commented 10 years ago

Yep, looks like I managed to mess my commit up as well as miss the explanation later in the chapter. I meant to commit an accumulator-based drop_value. Sigh.