<div dir="ltr"><div>Hi Jonathon!<br><br></div>You only catch some specific type of exception, everything else is simply past onwards. See end of p. 2/beginning of p. 3 here: <a href="http://community.haskell.org/~simonmar/papers/ext-exceptions.pdf">http://community.haskell.org/~simonmar/papers/ext-exceptions.pdf</a><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 2:24 PM, Jonathon Delgado <span dir="ltr"><<a href="mailto:voldermort@hotmail.com" target="_blank">voldermort@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm sure it makes sense! I'm not really following though.<br>
<br>
I understood typeclasses to be analogous to OO interfaces. So if a variable implements the Exception interface, and Exception implements the Show interface, then it should automatically support show.<br>
<br>
I take it this was wrong? How does the compiler use typeclasses if they're not interfaces?<br>
<span class="im HOEnZb"><br>
<br>
Francesco Ariis  wrote:<br>
<br>
> I'm trying to use<br>
>   catch (...) (\e -> putStrLn $ show e)<br>
> However, I get an error<br>
>   Ambiguous type variable ‘a0’ arising from a use of ‘show’ prevents the constraint ‘(Show a0)’ from being solved.<br>
> This goes away if I change the code to<br>
>   catch (...) (\e -> putStrLn $ show (e::IOException))<br>
><br>
> A couple of things I don't understand here:<br>
> - The signature for catch begins "Exception e", and exception it "class (Typeable e, Show e) => Exception e". So why isn't show automatically available?<br>
> - Why does the new code work at all? e is Exception, not IOException. What would happen if it caught a different Exception?<br>
<br>
</span><div class="HOEnZb"><div class="h5">IOException is a concrete type while Exception is a typeclass. In the end,<br>
the compiler needs the former, the latter not being enough.<br>
<br>
The code works as any other class-based function would<br>
<br>
    someFunction :: Monoid a -> [a] -> a<br>
    -- ^-- in the end `Monoid a` will become something concrete, like<br>
    -- a String, a Sum, etc.<br>
<br>
Does that make sense?<br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Markus Läll<br></div>
</div>