# Effective Haskell - inaccurate description of filter example (page 61)

**URL:** <https://forum.devtalk.com/t/effective-haskell-inaccurate-description-of-filter-example-page-61/139332>\
**Category:** PragProg Customers\
**Tags:** book-effective-haskell, errata\
**Created:** [12 January 2024 13:37 UTC](https://forum.devtalk.com/t/effective-haskell-inaccurate-description-of-filter-example-page-61/139332 "2024-01-12T13:37:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tusktenon](https://forum.devtalk.com/user_avatar/forum.devtalk.com/tusktenon/32/5844_2.png) [@tusktenon](https://forum.devtalk.com/u/tusktenon)\
**Post date:** [12 January 2024 13:37 UTC](https://forum.devtalk.com/t/effective-haskell-inaccurate-description-of-filter-example-page-61/139332/1 "2024-01-12T13:37:50Z")

</div>

@RebeccaSkinner

On p.61 in Chapter 2, the following is described as finding “the sum of the first ten odd numbers”:

```auto
λ (foldr (+) 0 . filter odd) [0..10]
25

```

In fact, this code sums the odd numbers between 0 and 10 – that is, the first _five_ odd numbers. For the sum of the first ten odd numbers, you’d probably want something like

```auto
λ (foldr (+) 0 . map (\x -> 2 * x + 1)) [0..9]
100

```

---

<div class="post-metadata">

**Author:** ![RebeccaSkinner](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rebeccaskinner/32/3888_2.png) [@RebeccaSkinner](https://forum.devtalk.com/u/RebeccaSkinner)\
**Post date:** [13 January 2024 00:48 UTC](https://forum.devtalk.com/t/effective-haskell-inaccurate-description-of-filter-example-page-61/139332/2 "2024-01-13T00:48:58Z")

</div>

You are correct, this is wrongly stated as being the first ten odd numbers rather than the odd numbers from 0 to 10.

---

<div class="post-metadata">

**Author:** ![tusktenon](https://forum.devtalk.com/user_avatar/forum.devtalk.com/tusktenon/32/5844_2.png) [@tusktenon](https://forum.devtalk.com/u/tusktenon)\
**Post date:** [13 January 2024 14:43 UTC](https://forum.devtalk.com/t/effective-haskell-inaccurate-description-of-filter-example-page-61/139332/3 "2024-01-13T14:43:33Z")

</div>

It’s actually not a bad example of the differing use cases for map and filter: if the problem is to “sum the odd numbers between _m_ and _n_,” then filter is perfect; if the problem is to “sum the first _n_ odd numbers,” map is more appropriate.

I’ve only made it to chapter 3 so far, but I’m really enjoying the book!
