[Haskell-cafe] Polymorphic function over pairs of maybes.

Jake McArthur jake.mcarthur at gmail.com
Tue Dec 28 20:32:48 CET 2010

Maybe something like this would work for you (requires the TypeFamilies 

     class FromMaybe a where
       type Maybe' a
       fromMaybe :: a -> Maybe' a -> a

     instance FromMaybe Int where
       type Maybe' Int = Maybe Int
       fromMaybe = Data.Maybe.fromMaybe

     instance FromMaybe String where
       type Maybe' String = Maybe String
       fromMaybe = Data.Maybe.fromMaybe

     instance (FromMaybe a, FromMaybe b) => FromMaybe (a, b) where
       type Maybe' (a, b) = (Maybe' a, Maybe' b)
       fromMaybe (x, y) (a, b) = (fromMaybe x a, fromMaybe y b)

- Jake McArthur

More information about the Haskell-Cafe mailing list