fork(1) download
  1. {-# LANGUAGE FlexibleInstances, TypeFamilies #-}
  2.  
  3. class Foo a where
  4. foo :: a
  5.  
  6. instance a ~ Int => Foo (String -> a) where
  7. foo = length
  8.  
  9. instance a ~ String => Foo a where
  10. foo = "world"
  11.  
  12. main = do
  13. print $ foo "hello"
  14. print $ foo
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:13:3:
    No instance for (Show a0) arising from a use of `print'
    The type variable `a0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Show Double -- Defined in `GHC.Float'
      instance Show Float -- Defined in `GHC.Float'
      instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus 23 others
    In the expression: print
    In a stmt of a 'do' block: print $ foo "hello"
    In the expression:
      do { print $ foo "hello";
           print $ foo }

prog.hs:13:11:
    Overlapping instances for Foo ([Char] -> a0)
      arising from a use of `foo'
    Matching instances:
      instance a ~ Int => Foo (String -> a) -- Defined at prog.hs:6:10
      instance a ~ String => Foo a -- Defined at prog.hs:9:10
    In the second argument of `($)', namely `foo "hello"'
    In a stmt of a 'do' block: print $ foo "hello"
    In the expression:
      do { print $ foo "hello";
           print $ foo }

prog.hs:14:3:
    No instance for (Show a1) arising from a use of `print'
    The type variable `a1' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Show Double -- Defined in `GHC.Float'
      instance Show Float -- Defined in `GHC.Float'
      instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus 23 others
    In the expression: print
    In a stmt of a 'do' block: print $ foo
    In the expression:
      do { print $ foo "hello";
           print $ foo }

prog.hs:14:11:
    Overlapping instances for Foo a1 arising from a use of `foo'
    Matching instances:
      instance a ~ String => Foo a -- Defined at prog.hs:9:10
      instance a ~ Int => Foo (String -> a) -- Defined at prog.hs:6:10
    (The choice depends on the instantiation of `a1'
     To pick the first instance above, use -XIncoherentInstances
     when compiling the other instance declarations)
    In the second argument of `($)', namely `foo'
    In a stmt of a 'do' block: print $ foo
    In the expression:
      do { print $ foo "hello";
           print $ foo }
stdout
Standard output is empty