Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • You can start with sum (x:xs) = g x xs immediately to avoid 0 + .... (Which only works because (+) 0 is essentially id for numeric types.) Commented Nov 3, 2018 at 8:49
  • 1
    but then I have to handle the [] case separately. With the explicit 0. It's unavoidable. Commented Nov 3, 2018 at 8:49
  • What do you mean by the last one (of the first code block) being in tail recursive form? Commented Nov 3, 2018 at 16:58
  • @DavidYoung in g x (y:xs) = g (x+y) xs, call to g is a tail call. Commented Nov 3, 2018 at 18:36