Discussion: add more idiomatic versions of catchJust and/or handleJust

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Discussion: add more idiomatic versions of catchJust and/or handleJust

David Feuer

The catchJust and handleJust functions seem a bit weird and unidiomatic.

catchJust
        :: Exception e
        => (e -> Maybe b)         -- ^ Predicate to select exceptions
        -> IO a                   -- ^ Computation to run
        -> (b -> IO a)            -- ^ Handler
        -> IO a
catchJust p a handler = catch a handler'
  where handler' e = case p e of
                        Nothing -> throwIO e
                        Just b  -> handler b

This takes two functions and then puts them together. I would think the more natural API would be

catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
catchMaybe m handler = catch m handler' where
  handler' e = fromMaybe (throwIO e) (handler e)

This is exactly as powerful as catchJust:

catchMaybe m handler = catchJust handler m id
catchJust p m handler = catchMaybe m $ fmap handler . p

But catchMaybe doesn't enforce the arbitrary separation between "selection" and "handling".


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Andreas Abel
I can only guess why catchJust was designed like it is.  A type like

   b -> Maybe (IO a)

is not as intuitive as the types

   e -> Maybe b
     -- ^ if you do not understand this, get back to Haskell school!

   b -> IO a
     -- ^ a continuation, we know this from >>= and friends

A type like  Maybe (IO a)  is more unusual, requires more thinking.

+-0. I have no opinion on what is better.

On 12.07.2016 02:23, David Feuer wrote:

> The catchJust and handleJust functions seem a bit weird and unidiomatic.
>
> catchJust
>          :: Exception e
>          => (e -> Maybe b)         -- ^ Predicate to select exceptions
>          -> IO a                   -- ^ Computation to run
>          -> (b -> IO a)            -- ^ Handler
>          -> IO a
> catchJust p a handler = catch a handler'
>    where handler' e = case p e of
>                          Nothing -> throwIO e
>                          Just b  -> handler b
>
> This takes two functions and then puts them together. I would think the
> more natural API would be
>
> catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
> catchMaybe m handler = catch m handler' where
>    handler' e = fromMaybe (throwIO e) (handler e)
>
> This is exactly as powerful as catchJust:
>
> catchMaybe m handler = catchJust handler m id
> catchJust p m handler = catchMaybe m $ fmap handler . p
>
> But catchMaybe doesn't enforce the arbitrary separation between
> "selection" and "handling".
>
>
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>


--
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

[hidden email]
http://www2.tcs.ifi.lmu.de/~abel/
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

David Feuer
I hate having to make arbitrary choices when writing code. With
`catchJust`, I have to decide what to calculate in the selector and
what to calculate in the handler. As far as I can tell, there's never
any reason to leave any calculation for the handler.

I don't think the `Maybe (IO a)` type is nearly as hard to think about
as exceptions themselves are. The handler either provides a recovery
action or it doesn't. The catchMaybe signature strikes me, personally,
as easier to understand, because I don't need to use parametricity to
string the pieces together.

On Wed, Jul 13, 2016 at 3:36 PM, Andreas Abel <[hidden email]> wrote:

> I can only guess why catchJust was designed like it is.  A type like
>
>   b -> Maybe (IO a)
>
> is not as intuitive as the types
>
>   e -> Maybe b
>     -- ^ if you do not understand this, get back to Haskell school!
>
>   b -> IO a
>     -- ^ a continuation, we know this from >>= and friends
>
> A type like  Maybe (IO a)  is more unusual, requires more thinking.
>
> +-0. I have no opinion on what is better.
>
>
> On 12.07.2016 02:23, David Feuer wrote:
>>
>> The catchJust and handleJust functions seem a bit weird and unidiomatic.
>>
>> catchJust
>>          :: Exception e
>>          => (e -> Maybe b)         -- ^ Predicate to select exceptions
>>          -> IO a                   -- ^ Computation to run
>>          -> (b -> IO a)            -- ^ Handler
>>          -> IO a
>> catchJust p a handler = catch a handler'
>>    where handler' e = case p e of
>>                          Nothing -> throwIO e
>>                          Just b  -> handler b
>>
>> This takes two functions and then puts them together. I would think the
>> more natural API would be
>>
>> catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
>> catchMaybe m handler = catch m handler' where
>>    handler' e = fromMaybe (throwIO e) (handler e)
>>
>> This is exactly as powerful as catchJust:
>>
>> catchMaybe m handler = catchJust handler m id
>> catchJust p m handler = catchMaybe m $ fmap handler . p
>>
>> But catchMaybe doesn't enforce the arbitrary separation between
>> "selection" and "handling".
>>
>>
>>
>> _______________________________________________
>> Libraries mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>
>
> --
> Andreas Abel  <><      Du bist der geliebte Mensch.
>
> Department of Computer Science and Engineering
> Chalmers and Gothenburg University, Sweden
>
> [hidden email]
> http://www2.tcs.ifi.lmu.de/~abel/
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Theodore Lief Gannon

+1 on catchMaybe from this corner of the peanut gallery, FWIW. It feels far more idiomatic, and provides the same power with fewer moving parts.

On Jul 13, 2016 1:14 PM, "David Feuer" <[hidden email]> wrote:
I hate having to make arbitrary choices when writing code. With
`catchJust`, I have to decide what to calculate in the selector and
what to calculate in the handler. As far as I can tell, there's never
any reason to leave any calculation for the handler.

I don't think the `Maybe (IO a)` type is nearly as hard to think about
as exceptions themselves are. The handler either provides a recovery
action or it doesn't. The catchMaybe signature strikes me, personally,
as easier to understand, because I don't need to use parametricity to
string the pieces together.

On Wed, Jul 13, 2016 at 3:36 PM, Andreas Abel <[hidden email]> wrote:
> I can only guess why catchJust was designed like it is.  A type like
>
>   b -> Maybe (IO a)
>
> is not as intuitive as the types
>
>   e -> Maybe b
>     -- ^ if you do not understand this, get back to Haskell school!
>
>   b -> IO a
>     -- ^ a continuation, we know this from >>= and friends
>
> A type like  Maybe (IO a)  is more unusual, requires more thinking.
>
> +-0. I have no opinion on what is better.
>
>
> On 12.07.2016 02:23, David Feuer wrote:
>>
>> The catchJust and handleJust functions seem a bit weird and unidiomatic.
>>
>> catchJust
>>          :: Exception e
>>          => (e -> Maybe b)         -- ^ Predicate to select exceptions
>>          -> IO a                   -- ^ Computation to run
>>          -> (b -> IO a)            -- ^ Handler
>>          -> IO a
>> catchJust p a handler = catch a handler'
>>    where handler' e = case p e of
>>                          Nothing -> throwIO e
>>                          Just b  -> handler b
>>
>> This takes two functions and then puts them together. I would think the
>> more natural API would be
>>
>> catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
>> catchMaybe m handler = catch m handler' where
>>    handler' e = fromMaybe (throwIO e) (handler e)
>>
>> This is exactly as powerful as catchJust:
>>
>> catchMaybe m handler = catchJust handler m id
>> catchJust p m handler = catchMaybe m $ fmap handler . p
>>
>> But catchMaybe doesn't enforce the arbitrary separation between
>> "selection" and "handling".
>>
>>
>>
>> _______________________________________________
>> Libraries mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>
>
> --
> Andreas Abel  <><      Du bist der geliebte Mensch.
>
> Department of Computer Science and Engineering
> Chalmers and Gothenburg University, Sweden
>
> [hidden email]
> http://www2.tcs.ifi.lmu.de/~abel/
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Ben Millwood
Am I right in thinking that `catch` is equivalent to
`catchJust fromException`? Perhaps the intention is that if you have an
implementation of `fromException` but haven't defined an instance of
`Exception` for whatever reason, you can use `catchJust` directly? Or if
you have a slight variant of `fromException` that isn't quite worth its
own typeclass instance? Analogously to `sortBy` vs. `sort`, for example.

I have no particular vote on the proposal and do not intend the above as
a defence of `catchJust`, just a possible perspective on it.

On Wed, Jul 13, 2016 at 02:23:04PM -0700, Theodore Lief Gannon wrote:

>+1 on catchMaybe from this corner of the peanut gallery, FWIW. It feels far
>more idiomatic, and provides the same power with fewer moving parts.
>On Jul 13, 2016 1:14 PM, "David Feuer" <[hidden email]> wrote:
>
>> I hate having to make arbitrary choices when writing code. With
>> `catchJust`, I have to decide what to calculate in the selector and
>> what to calculate in the handler. As far as I can tell, there's never
>> any reason to leave any calculation for the handler.
>>
>> I don't think the `Maybe (IO a)` type is nearly as hard to think about
>> as exceptions themselves are. The handler either provides a recovery
>> action or it doesn't. The catchMaybe signature strikes me, personally,
>> as easier to understand, because I don't need to use parametricity to
>> string the pieces together.
>>
>> On Wed, Jul 13, 2016 at 3:36 PM, Andreas Abel <[hidden email]>
>> wrote:
>> > I can only guess why catchJust was designed like it is.  A type like
>> >
>> >   b -> Maybe (IO a)
>> >
>> > is not as intuitive as the types
>> >
>> >   e -> Maybe b
>> >     -- ^ if you do not understand this, get back to Haskell school!
>> >
>> >   b -> IO a
>> >     -- ^ a continuation, we know this from >>= and friends
>> >
>> > A type like  Maybe (IO a)  is more unusual, requires more thinking.
>> >
>> > +-0. I have no opinion on what is better.
>> >
>> >
>> > On 12.07.2016 02:23, David Feuer wrote:
>> >>
>> >> The catchJust and handleJust functions seem a bit weird and unidiomatic.
>> >>
>> >> catchJust
>> >>          :: Exception e
>> >>          => (e -> Maybe b)         -- ^ Predicate to select exceptions
>> >>          -> IO a                   -- ^ Computation to run
>> >>          -> (b -> IO a)            -- ^ Handler
>> >>          -> IO a
>> >> catchJust p a handler = catch a handler'
>> >>    where handler' e = case p e of
>> >>                          Nothing -> throwIO e
>> >>                          Just b  -> handler b
>> >>
>> >> This takes two functions and then puts them together. I would think the
>> >> more natural API would be
>> >>
>> >> catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
>> >> catchMaybe m handler = catch m handler' where
>> >>    handler' e = fromMaybe (throwIO e) (handler e)
>> >>
>> >> This is exactly as powerful as catchJust:
>> >>
>> >> catchMaybe m handler = catchJust handler m id
>> >> catchJust p m handler = catchMaybe m $ fmap handler . p
>> >>
>> >> But catchMaybe doesn't enforce the arbitrary separation between
>> >> "selection" and "handling".
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> Libraries mailing list
>> >> [hidden email]
>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> >>
>> >
>> >
>> > --
>> > Andreas Abel  <><      Du bist der geliebte Mensch.
>> >
>> > Department of Computer Science and Engineering
>> > Chalmers and Gothenburg University, Sweden
>> >
>> > [hidden email]
>> > http://www2.tcs.ifi.lmu.de/~abel/
>> _______________________________________________
>> Libraries mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>

>_______________________________________________
>Libraries mailing list
>[hidden email]
>http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

David Menendez-2
In reply to this post by David Feuer
On Mon, Jul 11, 2016 at 8:23 PM, David Feuer <[hidden email]> wrote:

The catchJust and handleJust functions seem a bit weird and unidiomatic.

catchJust
        :: Exception e
        => (e -> Maybe b)         -- ^ Predicate to select exceptions
        -> IO a                   -- ^ Computation to run
        -> (b -> IO a)            -- ^ Handler
        -> IO a
catchJust p a handler = catch a handler'
  where handler' e = case p e of
                        Nothing -> throwIO e
                        Just b  -> handler b

This takes two functions and then puts them together. I would think the more natural API would be

catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
catchMaybe m handler = catch m handler' where
  handler' e = fromMaybe (throwIO e) (handler e)

This is exactly as powerful as catchJust:

catchMaybe m handler = catchJust handler m id
catchJust p m handler = catchMaybe m $ fmap handler . p

But catchMaybe doesn't enforce the arbitrary separation between "selection" and "handling”.

I wouldn’t call it an arbitrary separation. I imagine that the separation is deliberate, because you will frequently want to catch the same set of exceptions, but want to do different things in different contexts. With the current API, you can write a selector like “fileNotFound” and re-use it with multiple handlers.

In constrast, with a unified seletor/handler you have to write the same code to filter the exceptions you want with every handler which deals with them. You might as well just use catch.

--

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Oliver Charles-3
In reply to this post by David Feuer


On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <[hidden email]> wrote:

The catchJust and handleJust functions seem a bit weird and unidiomatic.

catchJust
        :: Exception e
        => (e -> Maybe b)         -- ^ Predicate to select exceptions
        -> IO a                   -- ^ Computation to run
        -> (b -> IO a)            -- ^ Handler
        -> IO a
catchJust p a handler = catch a handler'
  where handler' e = case p e of
                        Nothing -> throwIO e
                        Just b  -> handler b

This takes two functions and then puts them together. I would think the more natural API would be

catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
catchMaybe m handler = catch m handler' where
  handler' e = fromMaybe (throwIO e) (handler e)

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!

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.

Ollie

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

David Feuer
In reply to this post by David Menendez-2

I expect it'd be more common to use something like

catchMaybe m $ \e -> guard (isEOFException e) >> return ""

catchJust only makes sense if you not only need the same set of exceptions, but also the same non-trivial calculation based on the exception, for multiple handlers. A hypothetical catchOnly taking a Boolean predicate would make more sense for the case you describe.


On Jul 14, 2016 12:11 PM, "David Menendez" <[hidden email]> wrote:
On Mon, Jul 11, 2016 at 8:23 PM, David Feuer <[hidden email]> wrote:

The catchJust and handleJust functions seem a bit weird and unidiomatic.

catchJust
        :: Exception e
        => (e -> Maybe b)         -- ^ Predicate to select exceptions
        -> IO a                   -- ^ Computation to run
        -> (b -> IO a)            -- ^ Handler
        -> IO a
catchJust p a handler = catch a handler'
  where handler' e = case p e of
                        Nothing -> throwIO e
                        Just b  -> handler b

This takes two functions and then puts them together. I would think the more natural API would be

catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
catchMaybe m handler = catch m handler' where
  handler' e = fromMaybe (throwIO e) (handler e)

This is exactly as powerful as catchJust:

catchMaybe m handler = catchJust handler m id
catchJust p m handler = catchMaybe m $ fmap handler . p

But catchMaybe doesn't enforce the arbitrary separation between "selection" and "handling”.

I wouldn’t call it an arbitrary separation. I imagine that the separation is deliberate, because you will frequently want to catch the same set of exceptions, but want to do different things in different contexts. With the current API, you can write a selector like “fileNotFound” and re-use it with multiple handlers.

In constrast, with a unified seletor/handler you have to write the same code to filter the exceptions you want with every handler which deals with them. You might as well just use catch.

--

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

David Feuer
In reply to this post by Oliver Charles-3

That makes sense, I guess. Something like

data Handle a = Rethrow | Catch (IO a)

I suppose? My names are awful though.


On Jul 14, 2016 12:56 PM, "Oliver Charles" <[hidden email]> wrote:


On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <[hidden email]> wrote:

The catchJust and handleJust functions seem a bit weird and unidiomatic.

catchJust
        :: Exception e
        => (e -> Maybe b)         -- ^ Predicate to select exceptions
        -> IO a                   -- ^ Computation to run
        -> (b -> IO a)            -- ^ Handler
        -> IO a
catchJust p a handler = catch a handler'
  where handler' e = case p e of
                        Nothing -> throwIO e
                        Just b  -> handler b

This takes two functions and then puts them together. I would think the more natural API would be

catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
catchMaybe m handler = catch m handler' where
  handler' e = fromMaybe (throwIO e) (handler e)

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!

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.

Ollie

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Andreas Abel
Maybe rather

   data Handle a = Rethrow | Handle (IO a)

!?
On 14.07.2016 19:12, David Feuer wrote:

> That makes sense, I guess. Something like
>
> data Handle a = Rethrow | Catch (IO a)
>
> I suppose? My names are awful though.
>
>
> On Jul 14, 2016 12:56 PM, "Oliver Charles" <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>
>     On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <[hidden email]
>     <mailto:[hidden email]>> wrote:
>
>         The catchJust and handleJust functions seem a bit weird and
>         unidiomatic.
>
>         catchJust
>                  :: Exception e
>                  => (e -> Maybe b)         -- ^ Predicate to select
>         exceptions
>                  -> IO a                   -- ^ Computation to run
>                  -> (b -> IO a)            -- ^ Handler
>                  -> IO a
>         catchJust p a handler = catch a handler'
>            where handler' e = case p e of
>                                  Nothing -> throwIO e
>                                  Just b  -> handler b
>
>         This takes two functions and then puts them together. I would
>         think the more natural API would be
>
>         catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
>         catchMaybe m handler = catch m handler' where
>            handler' e = fromMaybe (throwIO e) (handler e)
>
>     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!
>
>     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.
>
>     Ollie
>
>
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>


--
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

[hidden email]
http://www2.tcs.ifi.lmu.de/~abel/
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Bardur Arantsson-2
On 07/14/2016 07:53 PM, Andreas Abel wrote:
> Maybe rather
>
>   data Handle a = Rethrow | Handle (IO a)
>

+1


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Oleg Grenrus
In reply to this post by David Feuer
Maybe pointing out the obvious, but when used with lens, catchJust approach is handy:

— | here catchJust is from `exceptions` though
catching :: MonadCatch m => Getting (First a) SomeException a -> m r -> (a -> m r) -> m r
catching l = catchJust (preview l)

http://hackage.haskell.org/package/lens-4.14/docs/src/Control.Exception.Lens.html#catching

+/- 0 on catchMaybe

- Oleg

> On 12 Jul 2016, at 03:23, David Feuer <[hidden email]> wrote:
>
> The catchJust and handleJust functions seem a bit weird and unidiomatic.
>
> catchJust
>         :: Exception e
>         => (e -> Maybe b)         -- ^ Predicate to select exceptions
>         -> IO a                   -- ^ Computation to run
>         -> (b -> IO a)            -- ^ Handler
>         -> IO a
> catchJust p a handler = catch a handler'
>   where handler' e = case p e of
>                         Nothing -> throwIO e
>                         Just b  -> handler b
>
> This takes two functions and then puts them together. I would think the more natural API would be
>
> catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
> catchMaybe m handler = catch m handler' where
>   handler' e = fromMaybe (throwIO e) (handler e)
>
> This is exactly as powerful as catchJust:
>
> catchMaybe m handler = catchJust handler m id
> catchJust p m handler = catchMaybe m $ fmap handler . p
>
> But catchMaybe doesn't enforce the arbitrary separation between "selection" and "handling".
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Bardur Arantsson-2
On 07/14/2016 08:06 PM, Oleg Grenrus wrote:
> Maybe pointing out the obvious, but when used with lens, catchJust approach is handy:
>
> — | here catchJust is from `exceptions` though
> catching :: MonadCatch m => Getting (First a) SomeException a -> m r -> (a -> m r) -> m r
> catching l = catchJust (preview l)
>
> http://hackage.haskell.org/package/lens-4.14/docs/src/Control.Exception.Lens.html#catching

lens is not a very appealing to have as a dependency if one is oneself
writing a library for others to consume. (Because of the huge set of
dependencies.)


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

David Feuer
In reply to this post by Andreas Abel

Handle is no good because it clashes with file handles. How about Reaction?


On Jul 14, 2016 1:53 PM, "Andreas Abel" <[hidden email]> wrote:
Maybe rather

  data Handle a = Rethrow | Handle (IO a)

!?
On 14.07.2016 19:12, David Feuer wrote:
That makes sense, I guess. Something like

data Handle a = Rethrow | Catch (IO a)

I suppose? My names are awful though.


On Jul 14, 2016 12:56 PM, "Oliver Charles" <[hidden email]
<mailto:[hidden email]>> wrote:



    On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <[hidden email]
    <mailto:[hidden email]>> wrote:

        The catchJust and handleJust functions seem a bit weird and
        unidiomatic.

        catchJust
                 :: Exception e
                 => (e -> Maybe b)         -- ^ Predicate to select
        exceptions
                 -> IO a                   -- ^ Computation to run
                 -> (b -> IO a)            -- ^ Handler
                 -> IO a
        catchJust p a handler = catch a handler'
           where handler' e = case p e of
                                 Nothing -> throwIO e
                                 Just b  -> handler b

        This takes two functions and then puts them together. I would
        think the more natural API would be

        catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
        catchMaybe m handler = catch m handler' where
           handler' e = fromMaybe (throwIO e) (handler e)

    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!

    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.

    Ollie



_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



--
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

[hidden email]
http://www2.tcs.ifi.lmu.de/~abel/

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Oliver Charles-3
data ExceptionHandler a = Rethrow | HandleException (IO a)

would be my offering of paint.

On Thu, Jul 14, 2016 at 9:52 PM David Feuer <[hidden email]> wrote:

Handle is no good because it clashes with file handles. How about Reaction?


On Jul 14, 2016 1:53 PM, "Andreas Abel" <[hidden email]> wrote:
Maybe rather

  data Handle a = Rethrow | Handle (IO a)

!?
On 14.07.2016 19:12, David Feuer wrote:
That makes sense, I guess. Something like

data Handle a = Rethrow | Catch (IO a)

I suppose? My names are awful though.


On Jul 14, 2016 12:56 PM, "Oliver Charles" <[hidden email]
<mailto:[hidden email]>> wrote:



    On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <[hidden email]
    <mailto:[hidden email]>> wrote:

        The catchJust and handleJust functions seem a bit weird and
        unidiomatic.

        catchJust
                 :: Exception e
                 => (e -> Maybe b)         -- ^ Predicate to select
        exceptions
                 -> IO a                   -- ^ Computation to run
                 -> (b -> IO a)            -- ^ Handler
                 -> IO a
        catchJust p a handler = catch a handler'
           where handler' e = case p e of
                                 Nothing -> throwIO e
                                 Just b  -> handler b

        This takes two functions and then puts them together. I would
        think the more natural API would be

        catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
        catchMaybe m handler = catch m handler' where
           handler' e = fromMaybe (throwIO e) (handler e)

    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!

    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.

    Ollie



_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



--
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

[hidden email]
http://www2.tcs.ifi.lmu.de/~abel/

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Carter Schonwald

At this point maybe it'd be better to write out these ideas as a library and implement a bunch of example codes for different approaches.  Changing the interfaces for exception handling code is subtle stuff!


On Jul 14, 2016 5:42 PM, "Oliver Charles" <[hidden email]> wrote:
data ExceptionHandler a = Rethrow | HandleException (IO a)

would be my offering of paint.

On Thu, Jul 14, 2016 at 9:52 PM David Feuer <[hidden email]> wrote:

Handle is no good because it clashes with file handles. How about Reaction?


On Jul 14, 2016 1:53 PM, "Andreas Abel" <[hidden email]> wrote:
Maybe rather

  data Handle a = Rethrow | Handle (IO a)

!?
On 14.07.2016 19:12, David Feuer wrote:
That makes sense, I guess. Something like

data Handle a = Rethrow | Catch (IO a)

I suppose? My names are awful though.


On Jul 14, 2016 12:56 PM, "Oliver Charles" <[hidden email]
<mailto:[hidden email]>> wrote:



    On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <[hidden email]
    <mailto:[hidden email]>> wrote:

        The catchJust and handleJust functions seem a bit weird and
        unidiomatic.

        catchJust
                 :: Exception e
                 => (e -> Maybe b)         -- ^ Predicate to select
        exceptions
                 -> IO a                   -- ^ Computation to run
                 -> (b -> IO a)            -- ^ Handler
                 -> IO a
        catchJust p a handler = catch a handler'
           where handler' e = case p e of
                                 Nothing -> throwIO e
                                 Just b  -> handler b

        This takes two functions and then puts them together. I would
        think the more natural API would be

        catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO a
        catchMaybe m handler = catch m handler' where
           handler' e = fromMaybe (throwIO e) (handler e)

    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!

    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.

    Ollie



_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



--
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

[hidden email]
http://www2.tcs.ifi.lmu.de/~abel/

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

David Thomas
I kinda like "ExceptionDisposition" for the type, no particular ideas
on the constructors.  Offered only in the spirit of tossing out ideas
- feel free to ignore me if it's not helpful :)

On Thu, Jul 14, 2016 at 3:20 PM, Carter Schonwald
<[hidden email]> wrote:

> At this point maybe it'd be better to write out these ideas as a library and
> implement a bunch of example codes for different approaches.  Changing the
> interfaces for exception handling code is subtle stuff!
>
>
> On Jul 14, 2016 5:42 PM, "Oliver Charles" <[hidden email]> wrote:
>>
>> data ExceptionHandler a = Rethrow | HandleException (IO a)
>>
>> would be my offering of paint.
>>
>> On Thu, Jul 14, 2016 at 9:52 PM David Feuer <[hidden email]> wrote:
>>>
>>> Handle is no good because it clashes with file handles. How about
>>> Reaction?
>>>
>>>
>>> On Jul 14, 2016 1:53 PM, "Andreas Abel" <[hidden email]> wrote:
>>>>
>>>> Maybe rather
>>>>
>>>>   data Handle a = Rethrow | Handle (IO a)
>>>>
>>>> !?
>>>> On 14.07.2016 19:12, David Feuer wrote:
>>>>>
>>>>> That makes sense, I guess. Something like
>>>>>
>>>>> data Handle a = Rethrow | Catch (IO a)
>>>>>
>>>>> I suppose? My names are awful though.
>>>>>
>>>>>
>>>>> On Jul 14, 2016 12:56 PM, "Oliver Charles" <[hidden email]
>>>>> <mailto:[hidden email]>> wrote:
>>>>>
>>>>>
>>>>>
>>>>>     On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <[hidden email]
>>>>>     <mailto:[hidden email]>> wrote:
>>>>>
>>>>>         The catchJust and handleJust functions seem a bit weird and
>>>>>         unidiomatic.
>>>>>
>>>>>         catchJust
>>>>>                  :: Exception e
>>>>>                  => (e -> Maybe b)         -- ^ Predicate to select
>>>>>         exceptions
>>>>>                  -> IO a                   -- ^ Computation to run
>>>>>                  -> (b -> IO a)            -- ^ Handler
>>>>>                  -> IO a
>>>>>         catchJust p a handler = catch a handler'
>>>>>            where handler' e = case p e of
>>>>>                                  Nothing -> throwIO e
>>>>>                                  Just b  -> handler b
>>>>>
>>>>>         This takes two functions and then puts them together. I would
>>>>>         think the more natural API would be
>>>>>
>>>>>         catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO
>>>>> a
>>>>>         catchMaybe m handler = catch m handler' where
>>>>>            handler' e = fromMaybe (throwIO e) (handler e)
>>>>>
>>>>>     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!
>>>>>
>>>>>     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.
>>>>>
>>>>>     Ollie
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Libraries mailing list
>>>>> [hidden email]
>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>>>>
>>>>
>>>>
>>>> --
>>>> Andreas Abel  <><      Du bist der geliebte Mensch.
>>>>
>>>> Department of Computer Science and Engineering
>>>> Chalmers and Gothenburg University, Sweden
>>>>
>>>> [hidden email]
>>>> http://www2.tcs.ifi.lmu.de/~abel/
>>
>>
>> _______________________________________________
>> Libraries mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Carter Schonwald
Again, at this juncture it sounds like effort would be better spent first writing out an alternative userland lib to understand these design ideas / articulate their impact better 

On Friday, July 15, 2016, David Thomas <[hidden email]> wrote:
I kinda like "ExceptionDisposition" for the type, no particular ideas
on the constructors.  Offered only in the spirit of tossing out ideas
- feel free to ignore me if it's not helpful :)

On Thu, Jul 14, 2016 at 3:20 PM, Carter Schonwald
<<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;carter.schonwald@gmail.com&#39;)">carter.schonwald@...> wrote:
> At this point maybe it'd be better to write out these ideas as a library and
> implement a bunch of example codes for different approaches.  Changing the
> interfaces for exception handling code is subtle stuff!
>
>
> On Jul 14, 2016 5:42 PM, "Oliver Charles" <<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;ollie@ocharles.org.uk&#39;)">ollie@...> wrote:
>>
>> data ExceptionHandler a = Rethrow | HandleException (IO a)
>>
>> would be my offering of paint.
>>
>> On Thu, Jul 14, 2016 at 9:52 PM David Feuer <<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;david.feuer@gmail.com&#39;)">david.feuer@...> wrote:
>>>
>>> Handle is no good because it clashes with file handles. How about
>>> Reaction?
>>>
>>>
>>> On Jul 14, 2016 1:53 PM, "Andreas Abel" <<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;andreas.abel@ifi.lmu.de&#39;)">andreas.abel@...> wrote:
>>>>
>>>> Maybe rather
>>>>
>>>>   data Handle a = Rethrow | Handle (IO a)
>>>>
>>>> !?
>>>> On 14.07.2016 19:12, David Feuer wrote:
>>>>>
>>>>> That makes sense, I guess. Something like
>>>>>
>>>>> data Handle a = Rethrow | Catch (IO a)
>>>>>
>>>>> I suppose? My names are awful though.
>>>>>
>>>>>
>>>>> On Jul 14, 2016 12:56 PM, "Oliver Charles" <<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;ollie@ocharles.org.uk&#39;)">ollie@...
>>>>> <mailto:<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;ollie@ocharles.org.uk&#39;)">ollie@...>> wrote:
>>>>>
>>>>>
>>>>>
>>>>>     On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;david.feuer@gmail.com&#39;)">david.feuer@...
>>>>>     <mailto:<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;david.feuer@gmail.com&#39;)">david.feuer@...>> wrote:
>>>>>
>>>>>         The catchJust and handleJust functions seem a bit weird and
>>>>>         unidiomatic.
>>>>>
>>>>>         catchJust
>>>>>                  :: Exception e
>>>>>                  => (e -> Maybe b)         -- ^ Predicate to select
>>>>>         exceptions
>>>>>                  -> IO a                   -- ^ Computation to run
>>>>>                  -> (b -> IO a)            -- ^ Handler
>>>>>                  -> IO a
>>>>>         catchJust p a handler = catch a handler'
>>>>>            where handler' e = case p e of
>>>>>                                  Nothing -> throwIO e
>>>>>                                  Just b  -> handler b
>>>>>
>>>>>         This takes two functions and then puts them together. I would
>>>>>         think the more natural API would be
>>>>>
>>>>>         catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO
>>>>> a
>>>>>         catchMaybe m handler = catch m handler' where
>>>>>            handler' e = fromMaybe (throwIO e) (handler e)
>>>>>
>>>>>     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!
>>>>>
>>>>>     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.
>>>>>
>>>>>     Ollie
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Libraries mailing list
>>>>> <a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;Libraries@haskell.org&#39;)">Libraries@...
>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>>>>
>>>>
>>>>
>>>> --
>>>> Andreas Abel  <><      Du bist der geliebte Mensch.
>>>>
>>>> Department of Computer Science and Engineering
>>>> Chalmers and Gothenburg University, Sweden
>>>>
>>>> <a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;andreas.abel@gu.se&#39;)">andreas.abel@...
>>>> http://www2.tcs.ifi.lmu.de/~abel/
>>
>>
>> _______________________________________________
>> Libraries mailing list
>> <a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;Libraries@haskell.org&#39;)">Libraries@...
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>
> _______________________________________________
> Libraries mailing list
> <a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;Libraries@haskell.org&#39;)">Libraries@...
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

David Feuer

You are very welcome to do so if you don't think further discussion will be useful. Those who feel otherwise may continue to discuss it.


On Jul 15, 2016 9:23 AM, "Carter Schonwald" <[hidden email]> wrote:
Again, at this juncture it sounds like effort would be better spent first writing out an alternative userland lib to understand these design ideas / articulate their impact better 

On Friday, July 15, 2016, David Thomas <[hidden email]> wrote:
I kinda like "ExceptionDisposition" for the type, no particular ideas
on the constructors.  Offered only in the spirit of tossing out ideas
- feel free to ignore me if it's not helpful :)

On Thu, Jul 14, 2016 at 3:20 PM, Carter Schonwald
<[hidden email]> wrote:
> At this point maybe it'd be better to write out these ideas as a library and
> implement a bunch of example codes for different approaches.  Changing the
> interfaces for exception handling code is subtle stuff!
>
>
> On Jul 14, 2016 5:42 PM, "Oliver Charles" <[hidden email]> wrote:
>>
>> data ExceptionHandler a = Rethrow | HandleException (IO a)
>>
>> would be my offering of paint.
>>
>> On Thu, Jul 14, 2016 at 9:52 PM David Feuer <[hidden email]> wrote:
>>>
>>> Handle is no good because it clashes with file handles. How about
>>> Reaction?
>>>
>>>
>>> On Jul 14, 2016 1:53 PM, "Andreas Abel" <[hidden email]> wrote:
>>>>
>>>> Maybe rather
>>>>
>>>>   data Handle a = Rethrow | Handle (IO a)
>>>>
>>>> !?
>>>> On 14.07.2016 19:12, David Feuer wrote:
>>>>>
>>>>> That makes sense, I guess. Something like
>>>>>
>>>>> data Handle a = Rethrow | Catch (IO a)
>>>>>
>>>>> I suppose? My names are awful though.
>>>>>
>>>>>
>>>>> On Jul 14, 2016 12:56 PM, "Oliver Charles" <[hidden email]
>>>>> <mailto:[hidden email]>> wrote:
>>>>>
>>>>>
>>>>>
>>>>>     On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <[hidden email]
>>>>>     <mailto:[hidden email]>> wrote:
>>>>>
>>>>>         The catchJust and handleJust functions seem a bit weird and
>>>>>         unidiomatic.
>>>>>
>>>>>         catchJust
>>>>>                  :: Exception e
>>>>>                  => (e -> Maybe b)         -- ^ Predicate to select
>>>>>         exceptions
>>>>>                  -> IO a                   -- ^ Computation to run
>>>>>                  -> (b -> IO a)            -- ^ Handler
>>>>>                  -> IO a
>>>>>         catchJust p a handler = catch a handler'
>>>>>            where handler' e = case p e of
>>>>>                                  Nothing -> throwIO e
>>>>>                                  Just b  -> handler b
>>>>>
>>>>>         This takes two functions and then puts them together. I would
>>>>>         think the more natural API would be
>>>>>
>>>>>         catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO
>>>>> a
>>>>>         catchMaybe m handler = catch m handler' where
>>>>>            handler' e = fromMaybe (throwIO e) (handler e)
>>>>>
>>>>>     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!
>>>>>
>>>>>     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.
>>>>>
>>>>>     Ollie
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Libraries mailing list
>>>>> [hidden email]
>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>>>>
>>>>
>>>>
>>>> --
>>>> Andreas Abel  <><      Du bist der geliebte Mensch.
>>>>
>>>> Department of Computer Science and Engineering
>>>> Chalmers and Gothenburg University, Sweden
>>>>
>>>> [hidden email]
>>>> http://www2.tcs.ifi.lmu.de/~abel/
>>
>>
>> _______________________________________________
>> Libraries mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Discussion: add more idiomatic versions of catchJust and/or handleJust

Carter Schonwald
Respectfully I disagree. 

You are pushing a breaking change to functionality in the base exception Api without 
a) demonstrating the Api is better
 b) understanding the impact on preexisting code that would needlessly break 
c) without doing a prototype outside of base to demonstrate that this alternative is better both in terms of the underlying library complexity and how the resulting application complexity changes.  

I am voicing an opinion other readers on the libraries list have on this matter but are too polite or wise to air this feedback publicly. 

The onus is on the proposer to demonstrate validity. 

Cheers 
-Carter 

On Friday, July 15, 2016, David Feuer <[hidden email]> wrote:

You are very welcome to do so if you don't think further discussion will be useful. Those who feel otherwise may continue to discuss it.


On Jul 15, 2016 9:23 AM, "Carter Schonwald" <<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;carter.schonwald@gmail.com&#39;);" target="_blank">carter.schonwald@...> wrote:
Again, at this juncture it sounds like effort would be better spent first writing out an alternative userland lib to understand these design ideas / articulate their impact better 

On Friday, July 15, 2016, David Thomas <<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;davidleothomas@gmail.com&#39;);" target="_blank">davidleothomas@...> wrote:
I kinda like "ExceptionDisposition" for the type, no particular ideas
on the constructors.  Offered only in the spirit of tossing out ideas
- feel free to ignore me if it's not helpful :)

On Thu, Jul 14, 2016 at 3:20 PM, Carter Schonwald
<[hidden email]> wrote:
> At this point maybe it'd be better to write out these ideas as a library and
> implement a bunch of example codes for different approaches.  Changing the
> interfaces for exception handling code is subtle stuff!
>
>
> On Jul 14, 2016 5:42 PM, "Oliver Charles" <[hidden email]> wrote:
>>
>> data ExceptionHandler a = Rethrow | HandleException (IO a)
>>
>> would be my offering of paint.
>>
>> On Thu, Jul 14, 2016 at 9:52 PM David Feuer <[hidden email]> wrote:
>>>
>>> Handle is no good because it clashes with file handles. How about
>>> Reaction?
>>>
>>>
>>> On Jul 14, 2016 1:53 PM, "Andreas Abel" <[hidden email]> wrote:
>>>>
>>>> Maybe rather
>>>>
>>>>   data Handle a = Rethrow | Handle (IO a)
>>>>
>>>> !?
>>>> On 14.07.2016 19:12, David Feuer wrote:
>>>>>
>>>>> That makes sense, I guess. Something like
>>>>>
>>>>> data Handle a = Rethrow | Catch (IO a)
>>>>>
>>>>> I suppose? My names are awful though.
>>>>>
>>>>>
>>>>> On Jul 14, 2016 12:56 PM, "Oliver Charles" <[hidden email]
>>>>> <mailto:[hidden email]>> wrote:
>>>>>
>>>>>
>>>>>
>>>>>     On Tue, 12 Jul 2016, 1:23 a.m. David Feuer, <[hidden email]
>>>>>     <mailto:[hidden email]>> wrote:
>>>>>
>>>>>         The catchJust and handleJust functions seem a bit weird and
>>>>>         unidiomatic.
>>>>>
>>>>>         catchJust
>>>>>                  :: Exception e
>>>>>                  => (e -> Maybe b)         -- ^ Predicate to select
>>>>>         exceptions
>>>>>                  -> IO a                   -- ^ Computation to run
>>>>>                  -> (b -> IO a)            -- ^ Handler
>>>>>                  -> IO a
>>>>>         catchJust p a handler = catch a handler'
>>>>>            where handler' e = case p e of
>>>>>                                  Nothing -> throwIO e
>>>>>                                  Just b  -> handler b
>>>>>
>>>>>         This takes two functions and then puts them together. I would
>>>>>         think the more natural API would be
>>>>>
>>>>>         catchMaybe :: Exception e => IO a -> (e -> Maybe (IO a)) -> IO
>>>>> a
>>>>>         catchMaybe m handler = catch m handler' where
>>>>>            handler' e = fromMaybe (throwIO e) (handler e)
>>>>>
>>>>>     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!
>>>>>
>>>>>     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.
>>>>>
>>>>>     Ollie
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Libraries mailing list
>>>>> [hidden email]
>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>>>>
>>>>
>>>>
>>>> --
>>>> Andreas Abel  <><      Du bist der geliebte Mensch.
>>>>
>>>> Department of Computer Science and Engineering
>>>> Chalmers and Gothenburg University, Sweden
>>>>
>>>> [hidden email]
>>>> http://www2.tcs.ifi.lmu.de/~abel/
>>
>>
>> _______________________________________________
>> Libraries mailing list
>> [hidden email]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>
> _______________________________________________
> Libraries mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>

_______________________________________________
Libraries mailing list
<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;Libraries@haskell.org&#39;);" target="_blank">Libraries@...
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
12