|
|
|
|
|
by lonelappde
2267 days ago
|
|
Haskell is lazy. a ++ b === (head a) : ((tail a) ++ b) (plus the base case) It is only linear when you force it to evaluate, which ideally happens only once (amortized) in your program when the result is consumed. As long as you are careful, you don't get the bad quadratic performance that you'd get from something like eagerly appending a character to a string in a loop in Java. There are either gotchas, though, including relying on the compiler to do things in constant space that naively look linear, and also knowing when the compiler won't help you and you have to structure your computation manually. |
|