Re: New draft (#4) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (02 Jun 2020 18:48 UTC)
Re: New draft (#4) of SRFI 189: Maybe and Either: optional container types Wolfgang Corcoran-Mathe (02 Jun 2020 19:08 UTC)
Re: New draft (#4) of SRFI 189: Maybe and Either: optional container types Wolfgang Corcoran-Mathe (02 Jun 2020 19:06 UTC)
Re: New draft (#4) of SRFI 189: Maybe and Either: optional container types Wolfgang Corcoran-Mathe (02 Jun 2020 19:12 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (04 Jun 2020 10:26 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (06 Jun 2020 16:59 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Wolfgang Corcoran-Mathe (07 Jun 2020 04:29 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (07 Jun 2020 10:28 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (14 Jun 2020 11:08 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (14 Jun 2020 16:08 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (14 Jun 2020 19:25 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (14 Jun 2020 20:57 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (15 Jun 2020 06:23 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (15 Jun 2020 08:25 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (16 Jun 2020 19:16 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (16 Jun 2020 19:18 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Wolfgang Corcoran-Mathe (17 Jun 2020 17:17 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Wolfgang Corcoran-Mathe (14 Jun 2020 19:25 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (14 Jun 2020 19:43 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Wolfgang Corcoran-Mathe (14 Jun 2020 20:28 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (14 Jun 2020 20:42 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Wolfgang Corcoran-Mathe (15 Jun 2020 13:13 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (16 Jun 2020 07:57 UTC)
Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Marc Nieper-Wißkirchen (06 Jun 2020 16:59 UTC)

Re: New draft (#5) of SRFI 189: Maybe and Either: optional container types Wolfgang Corcoran-Mathe 07 Jun 2020 04:29 UTC

On 2020-06-06 18:58 +0200, Marc Nieper-Wißkirchen wrote:
> >> (20) What about a `maybe-case' as well? In `maybe-if', the payload of
> >> the Just is thrown away, which is not what we always want.
> >>
> >> (define-syntax maybe-case
> >>   (syntax-rules (just nothing)
> >>     ((maybe-case e ((just . arg*) . body1) ((nothing) . body2))
> >>      (maybe-ref e (lambda () . body2) (lambda arg* body1)))))
> >>
> >> A similar definition can be made for `either-case'.
> >
> >
> > Can you explain the purpose of this?
>
> If you have code that consumes a Maybe, you can use `maybe-if' to turn
> different data paths (encoded by Maybe) into different code paths. But
> when you also need to know the payload, you would use `maybe-case':
>
> (maybe-case maybe
>   ((just x)
>    ;; maybe is a just and `x' is bound to the payload, which must be a
> single object in this case
>    ...)
>   ((nothing)
>    ;; maybe is a nothing
>    ...))

My first thought on seeing this form was that it's a special-purpose
pattern-matcher.  With some standardized general pattern-matching form,
it would of course be nice to be able to write something identical,
s/maybe-case/match/ (or whatever).  But maybe-case by itself doesn't
seem to add much; the following is equivalent to the above example,
and only one character longer:

    (maybe-ref
     maybe
     ;; maybe is a nothing
     (lambda () ...)
     ;; maybe is a just and `x' is bound to the payload, which must
     ;; be a single object in this case
     (lambda (x) ...))

The lambdas are a bit ugly, though.  I do think there's a need for a
syntactically higher-level (i.e. than maybe-ref) form for working with
Maybes.  Perhaps that's maybe-let*.

Regards,

--
Wolfgang Corcoran-Mathe  <xxxxxx@sigwinch.xyz>

"Quantum mechanics can be understood as the discovery that information
in nature is always finite." --Carlo Rovelli