I have two lists. One list contains some random data and other list contains the index of first list which needs to be deleted.
For example, let us consider two lists:
let a = [3,4,5,6,6,7,8]
let b = [1,3]
Then, the resultant output should be [3,5,6,7,8]. The number 4 and 6 are deleted since they are on index positions 1 and 3 respectively.
I’m new to Haskell, so finding it difficult to find the solution.
Update: Following code makes it work
import Data.List
dele :: Eq a => [a] -> [Int] -> [a]
dele [] _ = []
dele x [] = x
dele x (y:ys) = dele (delete (x !! y) x) ys
I was just wondering, is there a way to solve it through map/fold way ?
[0..]produces an infinite list[0, 1, 2, 3, ...]zipconstructs a list of pairs with the values of this list and your input list in the form[(0,x), (1, y), ...]filtertakes a functiona -> Bool. The lambda checks if the index (first element of the pair) is in your input listr.map sndreturns the second element of each pair of the zip list.zip,filter,mapandnotElemare documented here