Re: Maybe macros Marc Nieper-Wißkirchen 28 Jun 2020 17:43 UTC

Am So., 28. Juni 2020 um 19:26 Uhr schrieb Wolfgang Corcoran-Mathe
<xxxxxx@sigwinch.xyz>:

> This seems like the stickiest point to get right with these forms.
> I'd tentatively suggest the following.  If no expressions are passed
> to the maybe/either -and/-or forms,
>
> * maybe-or returns Nothing
>
> * maybe-and returns a Just whose payload is a single unspecified value
>
> * either-or returns a Left whose payload is a single unspecified value
>
> * either-and returns a Right whose payload is a single unspecified value
>
> For the last three forms: I find the container-of-no-values solution
> elegant, but I think single-valued containers are much easier to
> deal with (as John also notes).

If the values of the Maybe/Either returned by the empty `...-and' or
`...-or' forms are accessed to be processed further, the code is most
likely doing something very wrong. Zero values actually help here to
catch such logical errors because they will more likely raise an
error.

> The unit of the operations are,
> respectively, any Just/Left/Right, so it makes sense to me that we
> leave the payload unspecified.

Note that there is not *the* unit, but there are *"des"* units.
(Unfortunately, English as German is lacking the plural indefinite
article so I had resort to French.)

If you want to leave the payload unspecified, you should also leave
the number of unspecified values unspecified. That certainly makes
sense.

The best unit would be a Just/Left/Right for which it would be an
error to unwrap it. This could be some singleton value.