I am trying to implement a function in Haskell that'll take an arbitrary integer list xs and an integer k, and returns a set of lists with k in all possible positions.
For example, for a xs = [0, 1] and k = 2, we'd have
myFunction [0, 1] 2 = [ [2, 0, 1], [0, 2, 1], [0, 1, 2] ]
I've implemented it as
putOn xs x i = (take i xs) ++ (x:(drop i xs))
putOnAll xs x = map (putOn xs x) [0..(length xs)]
yet, I feel there must be other smarter ways to achieve the same. My code seems like someone trying to kill a bug with a missile. Could anyone make sugestions on ways to do something clever than this bit of code?
Thanks
 
     
     
     
    