I'm wondering if a list is a prefix of a second list, using the following code:
prefix :: [a] -> [b] -> Bool
prefix [] _ = True
prefix _ [] = False
prefix (x:xs) (y:ys) = if (x==y) then prefix xs ys else False
But it returns an error:
Inferred type is not general enough
*** Expression : prefix
*** Expected type : [a] -> [b] -> Bool
*** Inferred type : [a] -> [a] -> Bool
Can someone help me get this to work?
Your type signature claims the two lists can have different types, but they can't. So the compiler complains that it inferred a type that was less general than the one you asked for.