
What am I doing wrong in this admittedly contrived example? The code below will compile. It works as expected, unless I try to do "toMyParam Nothing". See below: λ: let arr = [P1 3.0, P2 'x'] λ: toMyParam False P2 'F' λ: toMyParam (Just 'x') P2 'x' λ: toMyParam Nothing <interactive>:38:1: No instance for (ToMyParam a0) arising from a use of `toMyParam' The type variable `a0' is ambiguous Code below: data MyParam = P1 Double | P2 Char deriving Show class ToMyParam a where toMyParam :: a -> MyParam instance ToMyParam Bool where toMyParam False = P2 'F' toMyParam True = P2 'T' instance ToMyParam Char where toMyParam = P2 instance ToMyParam Double where toMyParam = P1 instance ToMyParam a => ToMyParam (Maybe a) where toMyParam Nothing = P1 0.0 toMyParam (Just x) = toMyParam x