Could someone help me to understand this issue.
I have this simple function:
takeAsLong :: [a] -> (a -> Bool) -> [a]
takeAsLong [] _ = []
takeAsLong (x:xs) test | test x = x : takeAsLong xs test
| otherwise = []
But when I try to rewrite it using if-then-else I have an error.
takeAsLong :: [a] -> (a -> Bool) -> [a]
takeAsLong [] _ = []
takeAsLong (x:xs) test = if test x then x : takeAsLong [xs] test else []
The error is in the recursive call of "takeAsLong [xs] test" but I dont understand why it doesnt like it?
Error msg:
Couldn't match type ‘a’ with ‘[a]’ Expected: [a] -> Bool Actual: a -> Bool ‘a’ is a rigid type variable bound by the type signature for: takeAsLong :: forall a. [a] -> (a -> Bool) -> [a]
So why does it expect function test to be [a] -> Bool
and why version with guards doesnt have same issue?