リストのn番目の要素を複製したいのですが、haskellに関する知識は非常に限られています。リストを2つの部分に分割してから、最初の部分の最後の要素を取得して、それらの部分の間に貼り付けてみました。
dupl n (x:xs) = (take n (x:xs)) ++ ( (x:xs) !! n) ++ (drop n (x:xs))
しかし、私は常にエラーが発生します:
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.
誰かが私が間違っていることを教えてもらえますか?