Re: Usecase: chaining operations after "optionals" Lassi Kortela 10 Jun 2020 09:29 UTC

>      > (define (assoc-ref key alist)
>      >   (maybe-bind (list->maybe (assoc key alist)) cdr))
>      >
>      > It returns either a Nothing or Just the associated value.
>
>     Can Nothing be part of an alist?
>
> Yes; otherwise we would be in the same situation as with #f to indicate
> failure.
>
> The point is that the `assoc-ref' from above returns a positive result
> wrapped in a Just, which is never a Nothing, but which can, of course,
> wrap a Nothing.

There's always the standard `assoc` for the rare cases where one really
needs to distinguish between a missing entry / missing cdr and the
values #f/().

I think convenience procedures like `alist-ref` or `assoc?` should not
make the distinction. Then they can return a single value. SRFI 189
`lisp->maybe` can be used to convert that value to a Maybe.

In any case, alist convenience procedures are commonly needed enough
that they'd be better off not depending on fancier things like
Maybe/Either. Alist stuff is useful with R7RS-small, or even with
subsets of that language.