Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE TypeApplications, AllowAmbiguousTypes #-}
- {- old-style, but without extensions #-}
- import Data.Proxy
- {-
- data Proxy p = Proxy
- -}
- class Foo1 f where
- dofoo1 :: Proxy f -> IO ()
- instance Foo1 Int where
- dofoo1 _ = print 0
- instance Foo1 Double where
- dofoo1 _ = print 0.0
- bar1 :: IO ()
- bar1 = do
- dofoo1 (Proxy :: Proxy Int)
- dofoo1 (Proxy :: Proxy Double)
- {- with -XTypeApplications, -XAllowAmbiguousTypes -}
- class Foo2 f where
- dofoo2 :: IO ()
- instance Foo2 Int where
- dofoo2 = print 1
- instance Foo2 Double where
- dofoo2 = print 1.0
- bar2 :: IO ()
- bar2 = do
- dofoo2 @Int
- dofoo2 @Double
- main :: IO ()
- main = do
- bar1
- bar2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement