When I mention in the type signature of the function isQuestion
the types explicitly, GHCi compiles it perfectly:
isQuestion :: [Char] -> Maybe Bool
isQuestion [] = Nothing
isQuestion xs = Just (last xs == '?')
However, when I turn to 'generic' code, it doesn't work:
isQuestion :: [a] -> Maybe b
isQuestion [] = Nothing
isQuestion xs = Just (last xs == '?')
since I get the below error:
<interactive>:138:17: error:
* Couldn't match type `b' with `Bool'
`b' is a rigid type variable bound by
the type signature for:
isQuestion :: forall a b. [a] -> Maybe b
at <interactive>:136:1-28
Expected type: Maybe b
Actual type: Maybe Bool
* In the expression: Just (last xs == '?')
In an equation for `isQuestion':
isQuestion xs = Just (last xs == '?')
* Relevant bindings include
isQuestion :: [a] -> Maybe b (bound at <interactive>:137:1)