4 ms·
reverse (x:xs) = xs ++ [x] Does that really reverse a list in Haskell?
by tedunangst 17y ago
reverse (x:xs) = xs ++ [x]
Does that really reverse a list in Haskell?
- dons 17y agoIt's a "buggy" implementation (no recursive call) for the purpose of illustrating code coverage and quickcheck testing...
- tedunangst 17y agoThat's what I guessed, but the text doesn't make that clear at all.
- hristov 17y agoGood catch. I think it has to be: reverse (x:xs) = reverse(xs) ++ [x] But then again this is Haskell so there may be some mind boggling property of the language that is only understood by math postdocs and the more enlightened monks in Shaolin monasteries that makes the original line ok.
- steveklabnik 17y agoNope, your revised code is correct.
- jrockway 17y agoBut then again this is Haskell so there may be some mind boggling property of the language that is only understood by math postdocs and the more enlightened monks in Shaolin monasteries that makes the original line ok. Nope, and there never is. Haskell is just programming!
- deleted 17y ago[deleted]
- nearestneighbor 17y agohttp://www.reddit.com/r/programming/comments/bm1u8/safe_robust_programming_practices_in_haskell_via/c0ng5e6 http://www.reddit.com/r/programming/comments/bm1u8/safe_robu... Ironic, considering the title, if you ask me.