Advertisement
Guest User

Untitled

a guest
May 25th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. {-# LANGUAGE FlexibleContexts #-}
  2. {-# LANGUAGE IncoherentInstances #-}
  3. {-# LANGUAGE OverlappingInstances #-}
  4. {-# LANGUAGE FunctionalDependencies #-}
  5. {-# LANGUAGE FlexibleInstances #-}
  6. {-# LANGUAGE TypeFamilies #-}
  7. {-# LANGUAGE MultiParamTypeClasses #-}
  8. module Olaf where
  9.  
  10. {- |
  11.  
  12.  
  13. >>> eval (+) (1,2) :: Int
  14. 3
  15.  
  16. >>> eval (+) 1 2 :: Int
  17. 3
  18.  
  19. >>> eval (+) 1 (2 :: Int)
  20. 3
  21.  
  22. >>> eval (+) (1 :: Int) 2
  23. 3
  24.  
  25. >>> eval (,,) (1,2) 3
  26. (1,2,3)
  27.  
  28. >>> eval (,,) 1 (2,3) :: (Int,Int,Int)
  29. (1,2,3)
  30.  
  31.  
  32. -- the wrong instance is chosen:
  33.  
  34. >>> eval (+) (1 :: Int,2)
  35. ...
  36. ...No instance for (Show ((Int, ...) -> (Int, ...)))
  37. ...
  38.  
  39. >>> eval (,,) 1 (2,3)
  40. ...
  41. ...No instance for (Show (... -> ...
  42. ...
  43.  
  44. -}
  45.  
  46.  
  47. class Uncurry f r where
  48. eval :: f -> r
  49.  
  50. instance (a ~ a') => Uncurry a a' where
  51. eval = id
  52.  
  53. instance (a ~ a', Uncurry f (b -> c)) => Uncurry (a -> f) ((a', b) -> c) where
  54. eval f (a,b) = eval (f a) b
  55.  
  56. instance (a ~ a', Uncurry f c) => Uncurry (a -> f) (a' -> c) where
  57. eval f a = eval (f a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement