How to set value in nth element in a Haskell list?

haskell, list

Solution

Because Haskell is a functional language, you cannot 'edit' elements in lists, because everything is immutable. Instead, you can create a new list with something like:

take n xs ++ [newElement] ++ drop (n + 1) xs

However, it is not recommended in Haskell. For some more information you can see this post: Haskell replace element in list

Problem

I know that `xs !! n` gives me nth element in a list, but I don't know how to edit nth element in that list. Can you tell me how can I edit nth element in a list or give a hint at least? For example how can I make the second element `'a'` an `'e'` in this: `['s','t','a','c','k']`?

Original source

Related problems