<br><br><div class="gmail_quote"><div dir="ltr">On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <<a href="mailto:david.feuer@gmail.com">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">The catchJust and handleJust functions seem a bit weird and unidiomatic.</p>
<p dir="ltr">catchJust<br>
:: Exception e<br>
=> (e -> Maybe b) -- ^ Predicate to select 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</p>
<p dir="ltr">This takes two functions and then puts them together. I would think the more natural API would be</p>
<p dir="ltr">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)</p></blockquote></div><div><span style="font-size:13px">A point don't feel super strongly about, but feel I should raise, is that Nothing seems to be somewhat confusing. catchJust (\FileNotFound -> Nothing) seems to suggest that if FileNotFound occurs then nothing will happen, that is - the exception is ignored. However, that is not the case, rather than Nothing happening something certainly happens - an exception is (re)thrown!</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">Whether or not this confusion is likely to happen in practice I don't know, but it suggests a type isomorphic to Maybe is a better fit.</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">Ollie</span></div>