This is an indentation error: you have to indent the where clause, since otherwise Haskell will see the definition of f as a separate function. So we can fix it with:
mylength :: [Int] -> Int
mylength l = foldr f 0 l
where f :: Int -> Int -> Int
f x y = y+1
Nevertheless we can still make it more generic: instead of defining it for an [Int] list, we can define it over an [a] list, with:
mylength :: [a] -> Int
mylength l = foldr f 0 l
where f x y = y+1
We can also rewrite f as const (+1), so:
mylength :: Num n => [a] -> n
mylength = foldr (const (1+)) 0
Note that we can apply an eta-reduction here: remove l both in the head and the body of the mylength definition. Or in case we know that the number is also enumerable, we can use succ instead of (1+):
mylength :: (Enum n, Num n) => [a] -> n
mylength = foldr (const succ) 0