Abdessamad Abba
Abdessamad Abba

Reputation: 21

Reverse a list in haskell 3

example

I tried this

fon(x:y:xs) =reverse (x:xs)
fun (x:y:xs) = x : (fon xs)

Upvotes: 0

Views: 283

Answers (2)

chi
chi

Reputation: 116139

Since this looks like homework, I'll provide a hint.

You need both the original list and the reversed list. Try something like

foo :: [a] -> [a]
foo xs = bar xs (reverse xs)

bar :: [a] -> [a] -> [a]
...

Upvotes: 1

Random Dev
Random Dev

Reputation: 52280

what about this:

interweave :: [a] -> [a]
interweave zs = f zs (reverse zs)
    where f xs ys = concat $ zipWith (\ x y -> [x,y]) xs ys

example

λ> interweave [1..10]
[1,10,2,9,3,8,4,7,5,6,6,5,7,4,8,3,9,2,10,1]

Upvotes: 3

Related Questions