Is there any built-in function to replace an element at a given index in haskell?
Example:
replaceAtIndex(2,\"foo\",[\"bar\",\"bar\",\"bar\"])>
replaceAtIndex(2,\"foo\",[\"bar\",\"bar\",\"bar\"])
Try this solution:
import Data.List replaceAtIndex :: Int -> a -> [a] -> [a] replaceAtIndex i x xs = take i xs ++ [x] ++ drop (i+1) xs
It works as follows:
get the first i items, add the value 'x', add the rest of i+1 items