Comment

Comment by verroq

> You'd probably have even more ways to screw up like this with an OO language

My example was about imperative languages. You assertion on how many ways one could screw up on OO is irrelevant and besides, you'd really need a good understanding of OO to even try implementing those.

I didn't mean to use to imply any of those methods were bad. I have revised my post so people can't miss the point.

That is

> It is unfortunate when your ability to program functionally is directly proportional to how much of the standard library you have memorised. This makes functional programming much harder to learn.

Now, addressing your concerns.

> This page is a terrible example. Most of these are not not what a "reasonable programmer" would do.

All of the examples except for few particularly egregious ones seems reasonable to me.

For example

  -- one, need n+k patterns but so what
  fac  0    =  1
  fac (n+1) = (n+1) * fac n

  -- two
  fac 0 = 1
  fac n = n * fac (n-1)

  -- three
  fac n = foldl (*) 1 [1..n]

  -- four
  facs = scanl (*) 1 [1..]
  fac n = facs !! n

  -- five
  fac = foldr (*) 1 . enumFromTo 1

  -- six
  fac n = product [1..n]
Six fairly distinctive ways. I'm sure there's more that's as elegant if not more elegant ways to do the same thing.
parent verroq 14 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton