y :: (f->f) -> f
y f = f (y f)
indexOf :: Char -> String -> Maybe Int
indexOf c l =
y(\ ff c (h:t) pos ->
if ( c == h) then Just pos
else ff c t (pos + 1)
)(c, l, 0)
indexOf c [] = Nothing
It gives me two compilation errors: The code should find position of char c in string. For example: indexOf('a', 'lamp') = 2
Couldn't match expected type `[(Char, String, Integer)]
-> Integer -> Maybe Integer'
with actual type `Maybe Int'
The lambda expression `\ ff c (h : t) pos -> ...'
has four arguments,
but its type `((Char, String, Integer) -> Maybe Int)
-> (Char, String, Integer) -> Maybe Int'
has only two
In the first argument of `y', namely
`(\ ff c (h : t) pos
-> if (c == h) then Just pos else ff c t (pos + 1))'
In the expression:
y (\ ff c (h : t) pos
-> if (c == h) then Just pos else ff c t (pos + 1))
(c, l, 0)
Couldn't match expected type `[(Char, String, Integer)]
-> Integer -> Maybe Integer'
with actual type `Maybe Int'
The function `ff' is applied to three arguments,
but its type `(Char, String, Integer) -> Maybe Int' has only one
In the expression: ff c t (pos + 1)
In the expression: if (c == h) then Just pos else ff c t (pos + 1)
I don't know how to repair it. Please give me a hand :)
function a b c ...notfunction(a,b,c,...). The structure(a,b,c,...)is called a tuple, but the function defined doesn't take one.