fork download
  1. import qualified Control.Monad
  2.  
  3. data D c a b = D (c a b) (c b a)
  4.  
  5. apply :: (c a b -> c a2 b2) -> (c b a -> c b2 a2) -> D c a b -> D c a2 b2
  6. apply f1 f2 (D x y) = D (f1 x) (f2 y)
  7.  
  8. applyBoth = Control.Monad.join apply
  9.  
  10. f :: Int -> String
  11. f = show
  12.  
  13. g :: String -> Int
  14. g = read
  15.  
  16. h :: Int -> Int
  17. h = (*2)
  18.  
  19. join :: (a -> b) -> (c -> d) -> ((a, c) -> (b, d))
  20. join f g (x, y) = (f x, g y)
  21.  
  22. x1 = D f g
  23.  
  24. f1 = join h
  25.  
  26. y1 = apply f1 f1 x1 -- This compiles
  27. y2 = apply g g x1 where g = f1 -- Also works
  28.  
  29. z1 = applyBoth f1 x1 -- This fails
  30.  
  31. main = return ()
  32.  
Compilation error #stdin compilation error #stdout 0s 4552KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:29:19:
    Couldn't match type `[Char]' with `Int'
    Expected type: D (->) Int Int
      Actual type: D (->) Int String
    In the second argument of `applyBoth', namely `x1'
    In the expression: applyBoth f1 x1
    In an equation for `z1': z1 = applyBoth f1 x1
stdout
Standard output is empty