Advertisement
Guest User

Untitled

a guest
Oct 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE TypeApplications, AllowAmbiguousTypes #-}
  2.  
  3. {- old-style, but without extensions #-}
  4. import Data.Proxy
  5.  
  6. {-
  7.  
  8. data Proxy p = Proxy
  9.  
  10. -}
  11.  
  12. class Foo1 f where
  13.   dofoo1 :: Proxy f -> IO ()
  14.  
  15. instance Foo1 Int where
  16.   dofoo1 _ = print 0
  17.  
  18. instance Foo1 Double where
  19.   dofoo1 _ = print 0.0
  20.  
  21. bar1 :: IO ()
  22. bar1 = do
  23.   dofoo1 (Proxy :: Proxy Int)
  24.   dofoo1 (Proxy :: Proxy Double)
  25.  
  26.  
  27. {- with -XTypeApplications, -XAllowAmbiguousTypes -}
  28.  
  29. class Foo2 f where
  30.   dofoo2 :: IO ()
  31.  
  32. instance Foo2 Int where
  33.   dofoo2 = print 1
  34.  
  35. instance Foo2 Double where
  36.   dofoo2 = print 1.0
  37.  
  38. bar2 :: IO ()
  39. bar2 = do
  40.   dofoo2 @Int
  41.   dofoo2 @Double
  42.  
  43.  
  44. main :: IO ()
  45. main = do
  46.   bar1
  47.   bar2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement