I'm fooling with an example from Learn You a Haskell and I'm not sure what's going wrong. Here's the original example, which mimics truthy/falsey semantics:
class YesNo a where
yesno :: a -> Bool
A straightforward instance is given by:
instance YesNo Int where
yesno 0 = False
yesno _ = True
And then later:
instance YesNo (Maybe a) where
yesno (Just _) = True
yesno Nothing = False
This makes a certain amount of sense, but I find the notion that yesno (Just False) == True to be a little counterintuitive, and so I tried to modify it like so:
instance YesNo (Maybe a) where
yesno (Just b) = yesno b
yesno Nothing = False
So that in the case where the Maybe instance contains a value we get the truthiness of that value itself. However, this fails with the error No instance for (YesNo a) arising from a use ofyesno'`. What am I doing wrong?