<div dir="auto">Ah, I see. Thanks a lot for the clarification! <br><br><div data-smartmail="gmail_signature">Patrik Iselind</div></div><br><div class="gmail_quote"><div dir="ltr">Den fre 13 juli 2018 09:31Francesco Ariis <<a href="mailto:fa-ml@ariis.it">fa-ml@ariis.it</a>> skrev:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Jul 13, 2018 at 09:06:51AM +0200, mrx wrote:<br>
> That makes sense to me based on the type, sure. So read is some form of<br>
> casting then?<br>
<br>
Yep, but just from `String` and nothing else.<br>
<br>
> <br>
> Does this answers your question?<br>
> <br>
> <br>
> Maybe, but I still don't see what I'd use it for. Is it used to for example<br>
> read the contents of a file whose file name is provided as that string?<br>
<br>
No, you would use `readFile` for that:<br>
<br>
readFile :: FilePath -> IO String<br>
-- Filepath is a type synonym for `String`<br>
<br>
You would use `read` to convert simple user input (which is usually<br>
collected as String) into, say, Integers<br>
<br>
getLine :: IO String<br>
-- this could need read<br>
<br>
And in general, `Read` is supposed to be compatible with `Show`, so<br>
if you used `show` for any reason (some form of cheap serialisation,<br>
etc.), `read` should work back the type:<br>
<br>
λ> show [1..10]<br>
"[1,2,3,4,5,6,7,8,9,10]"<br>
λ> read it :: [Int]<br>
[1,2,3,4,5,6,7,8,9,10]<br>
<br>
tl;dr: cheap type parsing. For any more specialised/complex parsing,<br>
use a proper parsing library like Parsec.<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank" rel="noreferrer">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>