SHARE
TWEET

Untitled

a guest Oct 14th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top