fork download
  1. {-# LANGUAGE OverlappingInstances, MultiParamTypeClasses,
  2.   FunctionalDependencies, FlexibleContexts,
  3.   FlexibleInstances, UndecidableInstances #-}
  4.  
  5. import qualified Prelude
  6. import Prelude hiding ((+), (*))
  7. import qualified Prelude
  8.  
  9. newtype WInt = WInt { unwrap :: Int }
  10.  
  11. liftW f a b = WInt $ f (unwrap a) (unwrap b)
  12.  
  13. class Times a b c | a b -> c where
  14. (*) :: a -> b -> c
  15.  
  16. instance Times WInt WInt WInt where
  17. (*) = liftW (Prelude.*)
  18.  
  19. instance (Times a b c) => Times a (r -> b) (r -> c) where
  20. x * g = \v -> x * g v
  21.  
  22. instance Times (a -> b) a b where
  23. f * y = f y
  24.  
  25. two = WInt 2
  26. six = WInt 6
  27.  
  28. test :: WInt
  29. test = (two*(\x -> two*x))*six
  30.  
  31. 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:29:12:
    No instance for (Times WInt c0 c) arising from a use of `*'
    The type variables `c', `c0' 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 c => Times a (r -> b) (r -> c)
        -- Defined at prog.hs:19:10
      instance [overlap ok] Times WInt WInt WInt
        -- Defined at prog.hs:16:10
    Possible fix: add an instance declaration for (Times WInt c0 c)
    In the first argument of `(*)', namely `(two * (\ x -> two * x))'
    In the expression: (two * (\ x -> two * x)) * six
    In an equation for `test': test = (two * (\ x -> two * x)) * six

prog.hs:29:23:
    No instance for (Times WInt b0 c0) arising from a use of `*'
    The type variables `b0', `c0' 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 c => Times a (r -> b) (r -> c)
        -- Defined at prog.hs:19:10
      instance [overlap ok] Times WInt WInt WInt
        -- Defined at prog.hs:16:10
    Possible fix: add an instance declaration for (Times WInt b0 c0)
    In the expression: two * x
    In the second argument of `(*)', namely `(\ x -> two * x)'
    In the first argument of `(*)', namely `(two * (\ x -> two * x))'

prog.hs:29:27:
    No instance for (Times (b0 -> c) WInt WInt)
      arising from a use of `*'
    The type variables `c', `b0' are ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there is a potential instance available:
      instance [overlap ok] Times (a -> b) a b
        -- Defined at prog.hs:22:10
    Possible fix:
      add an instance declaration for (Times (b0 -> c) WInt WInt)
    In the expression: (two * (\ x -> two * x)) * six
    In an equation for `test': test = (two * (\ x -> two * x)) * six
stdout
Standard output is empty