Question: Write the function insertAt :: Int -> a -> [a] -> [a]. insertAt n x xs will insert the element x into the list xs

Write the function insertAt :: Int -> a -> [a] -> [a]. insertAt n x xs will insert the element x into the list xs at position n items from the beginning of xs. In other words, skip n items in xs, then insert the new element. You can assume that n will be a non-negative number. If n is greater than the length of the list xs then add it to the end of the list. For example insertAt 3 - "abcde" "abc-de" insertAt 2 100 [1..5] [1,2,100,3,4,5] Hint: Use standard prelude functions ++ and splitAt.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!