I have the following function:
replace :: a -> Int -> [a] -> [a]
replace elem 0 x:xs = elem : xs
replace elem i x:xs = x ++ replace elem (i - 1) xs
And GHCi tells me that I have an illegal literal in type error, specifically on the literal 0 in the first definition. Now, I'm aware that if I'm trying to replace an arbitrary item in a list that I should not be using the list data structure. That is fine, as I am planning on refactoring my program as soon as I can get what I want to work.
As far as the compiler complaint, I'm not really sure why Haskell believes I'm trying to define a type here. Any help with this would be much appreciated.
(x:xs)
instead ofx:xs
in the pattern andx :
instead ofx ++
. I'm not sure why it complains about type literals - when I compile it, I get "parse error in pattern: replace" which is what I would expect. – user2407038