3 ms·
I wonder if op can give a representative example (I am not a computer scientist). For instance, superficially, Fibonacci in C and in Haskell, look identical: F
by zeynel1 17y ago
I wonder if op can give a representative example (I am not a computer scientist). For instance, superficially, Fibonacci in C and in Haskell, look identical:
Fibonacci C
<<fib>>=
unsigned int fib(unsigned int n)
{
return n < 2 ? n : fib(n-1) + fib(n-2);
}
Fibonacci Haskell
<<fibonacci_recursive.hs>>=
fib :: Integer -> Integer
fib n
| n == 0 = 0
| n == 1 = 1
| n > 1 = fib (n-1) + fib (n-2)
From here: http://en.literateprograms.org/Fibonacci_numbers_(Haskell) http://en.literateprograms.org/Fibonacci_numbers_(Haskell)
- nostrademons 17y agoFibonacci in C would more often be written like this: unsigned int fib(unsigned int n) { int a = 1, b = 1, temp; for (int i = 2; i <= n; ++i) { temp = a + b; a = b; b = temp; } return b; } This also happens to be significantly more space and time efficient.