How to move an element in a list in Haskell? -
I am reading and reaching a place where I try to move an element in a list in the head I am here. I think what I think and I'm curious if someone can show me what the experienced Haskell programmers will do instead.
In this example, I have a list of interses and I want to move the '4' element, which will be index '3' at the top of the list.
Two Points = [1, 2, 3, 4, 5] (nums !! 3): Delete (nums !! 3) nums
Returns [4, 1, 2, 3, 5]
What do you think?
I will do this like this:
move as n In = head TS: (HS ++ tail TS) where (HS, TS) = split A
splits a list in the given position, it divides the two parts Which are created by splitting (here hs
and ts
) The element that should be brought forth is now at the beginning of ts
. Returns the first element of hs
, it returns everything the result of the first element of that element just adds these parts to the correct order: Hs
concatenated with tail ts
and element premedited by head ts
.
Comments
Post a Comment