Re: Extensibility (and the lack thereof) Felix Thibault 26 Oct 2020 21:17 UTC

On Mon, Oct 26, 2020 at 4:04 PM John Cowan <xxxxxx@ccil.org> wrote:
>
>
>
> On Mon, Oct 26, 2020 at 1:50 PM Wolfgang Corcoran-Mathe <xxxxxx@sigwinch.xyz> wrote:
>
>> I'd second this emphatically.  Few ideas suffer more from a restricted
>> view of Scheme types than pattern-matching.  Any number of extensions
>> seem plausible (what if we want our matcher to match ilists, boxes,
>> mappings, or some other type yet to be invented?), but, as noted
>> above, such extensions may break compatibility.
>
>
> I think the Right Thing here is to resurrect Haskell's idea of views (which are also present in Pure, by the way). Basically a view is a function that transforms an object of some opaque type (defined by a predicate, for Scheme purposes) into an object with a transparent type (most likely a list) that we know how to match on.  Then we just have to teach the matcher about (-> view-proc pattern), which applies view-proc to the object to be matched and matches the result against the pattern.
>
> See <https://gitlab.haskell.org/ghc/ghc/-/wikis/view-patterns> for details, some of which are unobvious (at least to me).  There are a LOT of other ideas at the bottom of that page, with links, but I think this one hits the sweet spot.  Support belongs in another SRFI, but I believe it is a reasonable extension.  I'd like to reserve patterns beginning with -> and => (these are valid in R6RS, so no problem there) in this SRFI, though.
>

Is reserving them a matter of adding them to the SRFI as reserved and
putting them in the macros as not-implemented-error?

Felix

>
>
> John Cowan          http://vrici.lojban.org/~cowan        xxxxxx@ccil.org
> A rabbi whose congregation doesn't want to drive him out of town isn't
> a rabbi, and a rabbi who lets them do it isn't a man.    --Jewish saying
>