I want to duplicate the n-th elemnt of a list and my knowledge of haskell is very limited. I tried splitting the list in two parts, then getting the last element of the first part and just pasting it between those parts:
dupl n (x:xs) = (take n (x:xs)) ++ ( (x:xs) !! n) ++ (drop n (x:xs))
But I always get the error:
Prelude> :l f.hs
[1 of 1] Compiling Main ( f.hs, interpreted )
f.hs:5:39:
Occurs check: cannot construct the infinite type: a0 = [a0]
In the first argument of `(:)', namely `x'
In the first argument of `(!!)', namely `(x : xs)'
In the first argument of `(++)', namely `((x : xs) !! n)'
Failed, modules loaded: none.
Could someone tell me what I am doing wrong?