I think the fib (n+2) = ... notation does not work and is a syntax error. You can use the regex style match for parameters, such as lists or tuples:
foo (x:xs) = ...
where x is the head of the list and xs is the rest of the list or
foo (x:[]) =
which matches if the list has only one item on the left and which is stored in x. Even difficult matches like
foo ((n,(x:xs)):rg) = ...
are possible. Function definitions in haskell is a complex topic, and there are many different styles that you can use.
Another possibility is to use a switch-case scheme:
foo fx | (fx) = [x] foo _ _ = []
In this case, the element "x" is wrapped in a list if condition (fx) true. In other cases, the parameters f and x are not interesting and an empty list is returned.
To fix your problem, I do not think that any of them is applicable, but why not use the function definition of the value of the remainder of the remainder parameter, for example:
fib n = (fib (n - 1)) + (fib (n - 2))
Hope this helps,
Oliver
source share