Since Proxy
contains no runtime information, there is never a need to pattern-match on the Proxy
constructor. So a common idiom is to abstract over the Proxy
datatype using a type variable.
showread :: forall proxy a. (Show a, Read a) => proxy a -> String -> String
showread _ = (show :: a -> String) . read
Now, if you happen to have an f a
in scope for some f
, you don't need to write out Proxy :: Proxy a
when calling f
.
ghci> let chars = "foo" -- chars :: [Char]
ghci> showread chars "'a'"
"'a'"