Haskell- Replace function in a list

1

They know if there is a predefined function in the haskell that gives an element, it replaces it with another element of a certain position in the list. For example:

func 1 2 [1,2,3,4]  
[1,2,1,4]
    
asked by anonymous 23.10.2017 / 09:26

1 answer

0

If you need to change elements in a given index, lists are not the framework for this. You could use Seq of Data.Sequence , in which case the function you are looking for is update :: Int -> a -> Seq a -> Seq a .

To do what you wanted in your example using the update would look like this:

> import Data.Sequence
> update 2 1 $ fromList [1,2,3,4]
fromList [1,2,1,4]

For more information see this link: link

    
24.10.2017 / 05:11