Re: SRFI 284: define-typed Dr. Arne Babenhauserheide 26 Sep 2026 07:11 UTC
Artyom Bologov <xxxxxx@aartaka.me> writes:

>> They are, yes. But I found no way to represent them cleanly while also
>> having the return types after the argument types, because
>> (a b c . d -> e)
>> is not a valid form.
>
> Indeed. Maybe an auxiliary syntax is in order? Something like ellipsis,
> I dunno:
>
> (a b c d ... -> e)
>
> scheme-index uses such a notation for variadic arguments, as it’s most
> parseable and clean, especially compared to the nastiness of dotted
> lists. Something to creatively steal?
>
>> And I don’t want to split the return type from the arguments.
>
> There are benefits in either way, but this is always an aesthetically
> charged personal decision, so it’s your call.
>
>> For define-typed* it would be possible to set a rest argument checking
>> procedure via #:rest, but this check procedure then also receives all
>> arguments defined via #:key.

>> (define-typed (foo a) (string? -> (λ (x) (string? x)))
>>   a)
>> (foo "")
>> (define-typed (foo a) (string? (-> (λ (x) (string? (car x)))))
>>   a)
>> (foo "")
>> (define-typed (foo a) (string? (-> (λ (x) (string? x))(λ (x)(string? x))))
>>   (values a a))
>> (foo "")
>
> Wow, this is a lot of syntax that the SRFI document does not describe,
> ahah. Need to formalize that too.

They are described in the document: (λ (x) (string? x)) is simply "a
lambda form". But it was missing that other forms that evaluate to a
predicate are allowed, too.

Throwing a ton of lambdas around is not how this is meant to be used
(because it kills readability), but it’s possible with the simple
structure.

>> I’m not well-versed in writing grammars, but I would gladly integrate
>> one. I can’t expect you to write it, but I’d be grateful if you did …
>
> It doesn’t have to be like Uber-Bachus-Naur-Super-Normal-Form-Grammar,
> it can be quite informal. Informal grammars are even more useful, I
> think—their crudeness and incompleteness forces you to express things in
> a simpler way.

Then I don’t think I really understood what you mean.

Can you give an example?

(I may be able to make something quickly from that)

Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
https://www.draketo.de