M
Malcolm McLean
Depends what you mean. I don't know Haskell so I've got to guess, but it looks likeIs your change of wording deliberate? I was talking about expressing an
algorithm, not implementing it. For example, here is one way to express
an algorithm whose value is the Fibonacci sequence (all of it!) in
Haskell:
fib = 1 : 1 : map (uncurry (+)) (zip fib (tail fib))
Now, this works on my machine, so it's implementable using just the
instructions my CPU executes, but it can't, I contend, be expressed in C
without totally distorting the meaning of the word "express".
the algorithm does a look up as a special case for 1 and 2, then does addition
to calculate the rest, by using the "tail recursion" optimisation.
In C you can express it a repeated addition, or recursively, but you can't easily
express that the definition is both recursive and implementable by repeated addition.
You can use big numbers in C, but not tidily. I don't know if Haskell allows you
to express that for many uses of the function, little integers will suffice.
We can easily enough get an array of Fibonnaci numbers in C. but it's much more
difficult to get both the array of numbers and the Nth number without using
N slots of memory.
So I'd say, yes, Haskell can express ideas that C can't. It can give a single interface to
an algorithm whilst C can only give one interface (unless you write highly complex
and non-idiomatic C).