Hi,
I like the SRFI because it can make the checks useful for direct
in-editor checking (and also that it can bring compatibility with the
define-typed¹ that I didn’t yet manage to turn into an SRFI, but whose
implementation enables such introspection by recording the types as
properties).
But I think the rationale would be stronger with less assertion and
instead starting right into the advantages.
I’d suggest:
Introspection of requirements for procedure arguments and guarantees of
return types enables programming support like as-you-type validity
checks. They help in setting the expectations, e.g., for what the
procedure accepts and what it returns. Or understanding what the
implementation-specific effective type for a value is.
This SRFI provides a way to fetch types et al. for procedures and return
values. It augment the declarative side of SRFI 253 and SRFI 273 with
more explanatory power, and to allow peeking behind the implementation
scaffolds for types.
(I would leave out the explanatory message)
¹ https://hg.sr.ht/~arnebab/guile-define-typed
An implementation for procedure-check-of using the define-typed
implementation in Guile would be:
(define (procedure-check-of proc)
(let* ((prop (procedure-properties proc))
(args (and=> (assoc 'argument-types prop) cdr))
(ret (and=> (assoc 'return-type prop) cdr)))
(values (if (list? args) args (list args))
(if (list? ret) ret (list ret)))))
To test:
(import (define-typed))
(define-typed (foo a) (integer? -> string?) (number->string a))
(foo 5)
;; $1 = "5"
(procedure-check-of foo)
;; $2 = (#<procedure integer? (_)>)
;; $3 = (#<procedure string? (_)>)
Best wishes,
Arne
--
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
https://www.draketo.de