fork download
  1. {-# Language MultiParamTypeClasses, FlexibleContexts, FlexibleInstances, IncoherentInstances, TypeFamilies, PatternGuards, FunctionalDependencies #-}
  2.  
  3. import Control.Monad
  4.  
  5.  
  6. class MConcat1 a b
  7.  
  8. where mConcat1 :: a -> [b]
  9.  
  10. instance MConcat1 [a] b => MConcat1 [[a]] b
  11.  
  12. where mConcat1 x = x >>= mConcat1
  13.  
  14. instance (a ~ b) => MConcat1 [a] b
  15.  
  16. where mConcat1 = id
  17.  
  18.  
  19. class MConcat2 a b
  20.  
  21. where mConcat2 :: a -> Maybe b
  22.  
  23. instance MConcat2 (Maybe a) b => MConcat2 (Maybe (Maybe a)) b
  24.  
  25. where mConcat2 x = x >>= mConcat2
  26.  
  27. instance (a ~ b) => MConcat2 (Maybe a) b
  28.  
  29. where mConcat2 = id
  30.  
  31.  
  32.  
  33. main = do print $ mConcat1 [[[123]],[[345]],[[222],[3333,5555]]]
  34. print $ mConcat1 [2345]
  35.  
  36. print $ mConcat2 (Just 123)
  37. print $ mConcat2 (Just $ Just 345)
Success #stdin #stdout 0s 4384KB
stdin
Standard input is empty
stdout
[123,345,222,3333,5555]
[2345]
Just 123
Just 345