'Why does the following code cause a "parse error (possibly incorrent indentation or mismatched brackets) at the next line of code

I'm attempting to create a replace function and the code below creates the error described in the post title in the first line of non-commented code following it. I have no idea as to why this is happening, so any help would be greatly appreciated.

 replace [] t r n = []
    replace [] _ _ _ = []
    replace xs _ _ 0 = xs
    replace (x:xs) t r n
         | x == t = r:(replace [xs] t r (n-1))
         | otherwise x (replace [xs] t r n)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source