fork(2) download
  1. {-# Language MultiParamTypeClasses, FlexibleContexts, FlexibleInstances, IncoherentInstances, TypeFamilies, PatternGuards, FunctionalDependencies #-}
  2.  
  3. import Control.Monad
  4.  
  5. class MonadConcat m a b
  6.  
  7. where monadConcat :: a -> m b
  8.  
  9. instance (Monad m, MonadConcat m (m a) b) => MonadConcat m (m (m a)) b
  10.  
  11. where monadConcat x = x >>= monadConcat
  12.  
  13. instance (Monad m, a ~ b) => MonadConcat m (m a) b
  14.  
  15. where monadConcat = id
  16.  
  17.  
  18. main = do print (monadConcat [[[123]],[[345]],[[222],[3333,5555]]] :: [Int])
  19. print (monadConcat [2345] :: [Int])
  20.  
  21. print (monadConcat (Just 123) :: Maybe Int)
  22. print (monadConcat (Just $ Just 345) :: Maybe Int)
Success #stdin #stdout 0s 4516KB
stdin
Standard input is empty
stdout
[123,345,222,3333,5555]
[2345]
Just 123
Just 345