[Haskell-cafe] Reading showables
John Ky
newhoggy at gmail.com
Sun Dec 7 20:44:37 EST 2008
Thanks for the clarification.
They're all the same, as you've explained:
Prelude> putStrLn $ (show . read) "123"
*** Exception: Prelude.read: no parse
Prelude> putStrLn $ show $ read "123"
*** Exception: Prelude.read: no parse
Prelude> putStrLn $ (\x -> show (read x)) "123"
*** Exception: Prelude.read: no parse
-John
On Mon, Dec 8, 2008 at 12:08 PM, Jonathan Cast <jonathanccast at fastmail.fm>wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081208/55c6de10/attachment.htm
More information about the Haskell-Cafe
mailing list