<p dir="ltr">Handle is no good because it clashes with file handles. How about Reaction?</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Jul 14, 2016 1:53 PM, "Andreas Abel" <<a href="mailto:andreas.abel@ifi.lmu.de">andreas.abel@ifi.lmu.de</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Maybe rather<br>
<br>
data Handle a = Rethrow | Handle (IO a)<br>
<br>
!?<br>
On 14.07.2016 19:12, David Feuer wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That makes sense, I guess. Something like<br>
<br>
data Handle a = Rethrow | Catch (IO a)<br>
<br>
I suppose? My names are awful though.<br>
<br>
<br>
On Jul 14, 2016 12:56 PM, "Oliver Charles" <<a href="mailto:ollie@ocharles.org.uk" target="_blank">ollie@ocharles.org.uk</a><br>
<mailto:<a href="mailto:ollie@ocharles.org.uk" target="_blank">ollie@ocharles.org.uk</a>>> wrote:<br>
<br>
<br>
<br>
On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a><br>
<mailto:<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>>> wrote:<br>
<br>
The catchJust and handleJust functions seem a bit weird and<br>
unidiomatic.<br>
<br>
catchJust<br>
:: Exception e<br>
=> (e -> Maybe b) -- ^ Predicate to select<br>
exceptions<br>
-> IO a -- ^ Computation to run<br>
-> (b -> IO a) -- ^ Handler<br>
-> IO a<br>
catchJust p a handler = catch a handler'<br>
where handler' e = case p e of<br>
Nothing -> throwIO e<br>
Just b -> handler b<br>
<br>
This takes two functions and then puts them together. I would<br>
think the more natural API would be<br>
<br>
catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a<br>
catchMaybe m handler = catch m handler' where<br>
handler' e = fromMaybe (throwIO e) (handler e)<br>
<br>
A point don't feel super strongly about, but feel I should raise, is<br>
that Nothing seems to be somewhat confusing. catchJust<br>
(\FileNotFound -> Nothing) seems to suggest that if FileNotFound<br>
occurs then nothing will happen, that is - the exception is ignored.<br>
However, that is not the case, rather than Nothing happening<br>
something certainly happens - an exception is (re)thrown!<br>
<br>
Whether or not this confusion is likely to happen in practice I<br>
don't know, but it suggests a type isomorphic to Maybe is a better fit.<br>
<br>
Ollie<br>
<br>
<br>
<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
<br>
</blockquote>
<br>
<br>
-- <br>
Andreas Abel <>< Du bist der geliebte Mensch.<br>
<br>
Department of Computer Science and Engineering<br>
Chalmers and Gothenburg University, Sweden<br>
<br>
<a href="mailto:andreas.abel@gu.se" target="_blank">andreas.abel@gu.se</a><br>
<a href="http://www2.tcs.ifi.lmu.de/~abel/" rel="noreferrer" target="_blank">http://www2.tcs.ifi.lmu.de/~abel/</a><br>
</blockquote></div></div>