For starters, you don't need to have parentheses around get . However, the syntax for the whole definition looks a bit. I assume you need something like this:
get :: [a] -> Int -> a get (x:xs) 0 = x get (x:xs) (n+1) = xs `get` n
Pay attention to the inverse elements around get to use its infix, which is necessary here because the rules for an alphanumeric identifier are different from operators: Operators are made of characters, are default infixes and write them without arguments or use their prefix, you put them in parentheses. Alphanumeric identifiers are prefixes by default, and surrounding them with reverse windows allow their infix to be used.
You can also use the inverse elements on the left side if you want, but it looks a bit strange:
(x:xs) `get` 0 = x (x:xs) `get` (n+1) = xs `get` n
By the way, the syntax of the n+1 template is deprecated, so you probably shouldn't use it. Instead, do the following:
(x:xs) `get` n = xs `get` (n - 1)
source share