Well, my goal when I first wrote it was to see if I could write reverse
without calling any other functions.
I did realize that it was really bad. :)
-- Lennart
On 9/23/07, Felipe Almeida Lessa <[EMAIL PROTECTED]> wrote:
>
> On 9/23/07, Lennart Augustsson <[EMAIL PROTECTED]> wrote:
> > If we're
On 9/23/07, Lennart Augustsson <[EMAIL PROTECTED]> wrote:
> If we're discussing bad versions of reverse, don't forget this one:
>
> rev [] = []
> rev (x:xs) =
> case rev xs of
> [] -> [x]
> y:ys -> y : rev (x : rev ys)
>
> It's different from most versions of reverse because it doesn't
If we're discussing bad versions of reverse, don't forget this one:
rev [] = []
rev (x:xs) =
case rev xs of
[] -> [x]
y:ys -> y : rev (x : rev ys)
It's different from most versions of reverse because it doesn't use any
auxiliarry functions.
It's also extremely inefficient.
-- Lenna
On 9/23/07, Thomas Hartman <[EMAIL PROTECTED]> wrote:
> -- this is the usual implementation right?
> myreverse xs = foldl f [] xs
> where f accum el = el : accum
This is often written
reverse = foldl (flip (:)) []
which I quite like, because you can contrast it with
foldr (:) []
which of
On Sat, 2007-09-22 at 21:14 -0700, Thomas Hartman wrote:
> I came up with the following functions to do "reverse." The first one
> is obviously bad, because of the expensive list concat. The last one,
> "myreverse", I think is the reference implementation you get in the
> prelude. The ones between,
I came up with the following functions to do "reverse." The first one
is obviously bad, because of the expensive list concat. The last one,
"myreverse", I think is the reference implementation you get in the
prelude. The ones between, I'm not so sure. I suspect they're "naive"
as the name indicates