[Haskell-cafe] Reading showables
Jonathan Cast
jonathanccast at fastmail.fm
Sun Dec 7 20:08:33 EST 2008
On Mon, 2008-12-08 at 11:16 +1100, John Ky wrote:
> Hi Thomas,
>
> So "show . read" and "\x -> show (read x)" are actually mean different
> things?
No. Of course not. But there's no guarantee that
show (read x) = x
either.
> Also, I never suspected that something like this should succeed:
>
> putStrLn $ (read . show) $ "!@#%$^DFD"
Of course it succeeds. You put the `show' first; show always succeeds
and --- for the Show instances in the Prelude, plus some ---
read (show x) = x
for finite, total x.
(Note that read . show /= show . read; they don't even have the same
type!
show . read :: forall alpha. Show alpha => String -> String
read . show :: forall alpha beta. (Read alpha, Show beta) => alpha ->
beta
NB: The reason why show . read is illegal should be screaming out at you
about now. The caveat --- other than the one I mentioned above --- to
claims that read . show = id should also be screaming out.)
jcc
More information about the Haskell-Cafe
mailing list