fork(1) 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. source1 :: [[[Int]]]
  19. source1 = [[[123]],[[345]],[[222],[3333,5555]]]
  20.  
  21. source2 :: [Int]
  22. source2 = [2345]
  23.  
  24. --result1 :: [Int]
  25. result1 = monadConcat source1
  26.  
  27. --result2 :: [Int]
  28. result2 = monadConcat source2
  29.  
  30. main = do print $ result1
  31. print $ result2
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:25:11: error:
    • No instance for (MonadConcat m1 [[[Int]]] b1)
        arising from a use of ‘monadConcat’
    • In the expression: monadConcat source1
      In an equation for ‘result1’: result1 = monadConcat source1

prog.hs:28:11: error:
    • No instance for (MonadConcat m0 [Int] b0)
        arising from a use of ‘monadConcat’
    • In the expression: monadConcat source2
      In an equation for ‘result2’: result2 = monadConcat source2

prog.hs:30:11: error:
    • Ambiguous type variables ‘m1’, ‘b1’ arising from a use of ‘print’
      prevents the constraint ‘(Show (m1 b1))’ from being solved.
      Probable fix: use a type annotation to specify what ‘m1’, ‘b1’ should be.
      These potential instances exist:
        instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
        instance (Show a, Show b) => Show (a, b) -- Defined in ‘GHC.Show’
        instance (Show a, Show b, Show c) => Show (a, b, c)
          -- Defined in ‘GHC.Show’
        ...plus 13 others
        ...plus one instance involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In a stmt of a 'do' block: print $ result1
      In the expression:
        do { print $ result1;
             print $ result2 }
      In an equation for ‘main’:
          main
            = do { print $ result1;
                   print $ result2 }

prog.hs:31:11: error:
    • Ambiguous type variables ‘m0’, ‘b0’ arising from a use of ‘print’
      prevents the constraint ‘(Show (m0 b0))’ from being solved.
      Probable fix: use a type annotation to specify what ‘m0’, ‘b0’ should be.
      These potential instances exist:
        instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
        instance (Show a, Show b) => Show (a, b) -- Defined in ‘GHC.Show’
        instance (Show a, Show b, Show c) => Show (a, b, c)
          -- Defined in ‘GHC.Show’
        ...plus 13 others
        ...plus one instance involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In a stmt of a 'do' block: print $ result2
      In the expression:
        do { print $ result1;
             print $ result2 }
      In an equation for ‘main’:
          main
            = do { print $ result1;
                   print $ result2 }
stdout
Standard output is empty