fork(3) download
  1. {-# LANGUAGE OverlappingInstances, MultiParamTypeClasses,
  2.   FunctionalDependencies, FlexibleContexts,
  3.   FlexibleInstances, UndecidableInstances,
  4.   NoMonomorphismRestriction #-}
  5.  
  6. import qualified Prelude
  7. import Prelude hiding ((+), (*))
  8. import Prelude ()
  9.  
  10. class Times a b c | a b -> c where
  11. (*) :: a -> b -> c
  12.  
  13. instance Times Int Int Int where
  14. (*) = (Prelude.*)
  15.  
  16. instance Times Double Double Double where
  17. (*) = (Prelude.*)
  18.  
  19. instance (Times a b c) => Times a (Matrix b) (Matrix c) where
  20. l * (r', c', m) = (r', c', \i -> l * m i)
  21.  
  22. instance Times (b -> c) (a -> b) (a -> c) where
  23. f * g = f . g
  24.  
  25. instance (Times a b c) => Times a (r -> b) (r -> c) where
  26. x * g = \v -> x * g v
  27.  
  28. instance Times (a -> b) a b where
  29. f * y = f y
  30.  
  31. type Matrix a = (Int, Int, (Int, Int) -> a)
  32.  
  33. test = (2*(\x -> 2*x))*6
  34.  
  35. main = undefined
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:33:1:
    Could not deduce (Times a1 b0 c1)
      arising from the ambiguity check for `test'
    from the context (Num a,
                      Num a2,
                      Num b,
                      Times (b1 -> c) b c2,
                      Times a (b1 -> c3) (b1 -> c),
                      Times a2 b1 c3)
      bound by the inferred type for `test':
                 (Num a, Num a2, Num b, Times (b1 -> c) b c2,
                  Times a (b1 -> c3) (b1 -> c), Times a2 b1 c3) =>
                 c2
      at prog.hs:33:1-24
    The type variables `a1', `b0', `c1' are ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance [overlap ok] Times (a -> b) a b
        -- Defined at prog.hs:28:10
      instance [overlap ok] Times a b c => Times a (r -> b) (r -> c)
        -- Defined at prog.hs:25:10
      instance [overlap ok] Times (b -> c) (a -> b) (a -> c)
        -- Defined at prog.hs:22:10
      ...plus three others
    When checking that `test'
      has the inferred type `forall c b c1 a a1 b1 c2.
                             (Num a, Num a1, Num b, Times (b1 -> c) b c1,
                              Times a (b1 -> c2) (b1 -> c), Times a1 b1 c2) =>
                             c1'
    Probable cause: the inferred type is ambiguous
stdout
Standard output is empty