# [Haskell-cafe] I read somewhere that for 90% of a wide class of computing problems, you only need 10% of the source code in Haskell, that you would in an imperative language.

Dominic Espinosa dcespin at fastmail.fm
Wed Sep 30 23:28:29 EDT 2009

```On Wed, Sep 30, 2009 at 11:10:19PM -0400, John Dorsey wrote:
> > Well, try this: Go ask a random person how you add up a list of numbers.
> > Most of them will say something about adding the first two together,
> > adding the third to that total, and so forth. In other words, the step
> > by step instructions.
>
> You word the (hypothetical) question with a bias toward imperative
> thinking.  You're asking "How do you do this action?"
>
> Why isn't the question "What is the sum of a list of numbers?", which is
> biased toward the declarative?

Indeed! Surely a person asked to "sum a list of numbers" such as
[45,82,78] will do exactly this: 45 + 82 + 78, proceeding to add 82 to
45, noting the intermediate sum, and then adding 78 to that. It's
certainly a fold, though our (non-programmer) subject here probably
wouldn't call it that.  Generalizing this pattern to non-arithmetical
situations is an 'FP trick' (or pattern, or what-have-you).  Also, he or
she would probably not understand what we know as 'foldl' or 'foldr'
immediately because the idea of a 'starting value' is not that clear --
the task statement of 'add a list of numbers' seems to presuppose that
there are numbers to be added, i.e. the list is not empty.

Assuredly the subject would not (mentally) count how many numbers were
in the list, set up a 'counter', and then execute an addition operation
that many times, storing the result in a 'temporary variable'.

In both cases our anonymous non-programmer understands the idea of
recursive/iterative addition, but does not know about the general
pattern of 'fold' or 'for(...) { ... }'. These are learned from
programming books. Most of these books teach some imperative language,
so, many programmers get used to the one and then have some difficulty
re-tooling mentally for the other. I know I did when I first began using
Haskell, but now the lack of folds in, say, C really hurts. :) Whoever
commented earlier in the thread that learning haskell is bad for your
brain because you pine for it when you program in other languages was
right on.
```