Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. {-# LANGUAGE ScopedTypeVariables #-}
  2. module ProxyExample where
  3.  
  4. ------------------------
  5.  
  6. import Data.Proxy
  7. import Prelude
  8.  
  9. -------------------------
  10.  
  11. -- This will not compile:
  12. -- showread :: String -> String
  13. -- showread = show . read
  14. -- ScopedTypeVariables: otherwise refering a is not possible
  15. --
  16. -- showread (Proxy :: Proxy Int) "3"
  17. -- "3"
  18. -- showread (Proxy :: Proxy Bool) "'fail'"
  19. -- **exception**
  20.  
  21.  
  22. showread :: forall a. (Show a, Read a) => Proxy a -> String -> String
  23. showread _ = (show :: a -> String) . read
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement