[Haskell-beginners] The type class Read

mrx patrik.mrx at gmail.com
Fri Jul 13 07:06:51 UTC 2018


Den tors 12 juli 2018 13:15Francesco Ariis <fa-ml at ariis.it> skrev:

> Hello Patrik,
>
> On Thu, Jul 12, 2018 at 12:05:52PM +0200, mrx wrote:
> > Why is the type class called `Read`?
> > What am I missing above?
>
> we can say any instance of `Read` has to implement
>
>     read :: Read a => String -> a
>     -- the actual instance implements a different function,
>     -- but that's not relevant for our example
>
> So, a typeclass (Read, capital `r`) gives us a function (`read`,
> lower-case `r`).  The function goes from  `String` (and no other
> things) to our implemented type.
>

That makes sense to me based on the type, sure. So read is some form of
casting then?

Does this answers your question?


Maybe, but I still don't see what I'd use it for. Is it used to for example
read the contents of a file whose file name is provided as that string?

// Patrik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180713/fe4f9145/attachment.html>


More information about the Beginners mailing list