Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 1.04 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why doesn't this function signature typecheck?
  2. data MyEither a b = MyLeft a | MyRight b
  3.                     deriving (Read, Show)
  4.  
  5. extractEither :: MyEither a b -> c
  6. extractEither (MyLeft p) = p
  7.        
  8. Couldn't match type `a' with `c'
  9.   `a' is a rigid type variable bound by
  10.       the type signature for extractEither :: MyEither a b -> c
  11.       at /Users/tongmuchenxuan/playground/test.hs:5:1
  12.   `c' is a rigid type variable bound by
  13.       the type signature for extractEither :: MyEither a b -> c
  14.       at /Users/tongmuchenxuan/playground/test.hs:5:1
  15. In the expression: p
  16. In an equation for `extractEither': extractEither (MyLeft p) = p
  17.        
  18. extractEither :: MyEither a a -> a
  19. extractEither (MyLeft p) = p
  20. extractEither (MyRight p) = p
  21.        
  22. extractMyLeft :: MyEither a b -> Maybe a
  23. extractMyRight :: MyEither a b -> Maybe b
  24.        
  25. extractEither :: (a -> c) -> (b -> c) -> MyEither a b -> c
  26. extractEither f g (MyLeft x)  = f x
  27. extractEither f g (MyRight y) = g y
  28.        
  29. extractEither :: MyEither a b -> c
  30. extractEither (MyLeft p) = p
  31.        
  32. public Object blah(Foo whatever);