{-# Language MultiParamTypeClasses, FlexibleContexts, FlexibleInstances, IncoherentInstances, TypeFamilies, PatternGuards, FunctionalDependencies #-} import Control.Monad class MConcat1 a b where mConcat1 :: a -> [b] instance MConcat1 [a] b => MConcat1 [[a]] b where mConcat1 x = x >>= mConcat1 instance (a ~ b) => MConcat1 [a] b where mConcat1 = id class MConcat2 a b where mConcat2 :: a -> Maybe b instance MConcat2 (Maybe a) b => MConcat2 (Maybe (Maybe a)) b where mConcat2 x = x >>= mConcat2 instance (a ~ b) => MConcat2 (Maybe a) b where mConcat2 = id main = do print $ mConcat1 [[[123]],[[345]],[[222],[3333,5555]]] print $ mConcat1 [2345] print $ mConcat2 (Just 123) print $ mConcat2 (Just $ Just 345)