From: Maxime Devos <maximedevos@telenet.be>
To: Artyom Bologov <mail@aartaka.me>,
"guile-devel@gnu.org" <guile-devel@gnu.org>
Subject: RE: Type declarations and data validation utils?
Date: Sun, 21 Jul 2024 19:13:47 +0200 [thread overview]
Message-ID: <20240721191330.qHDW2C0040wtc8B01HDWpb@laurent.telenet-ops.be> (raw)
In-Reply-To: <87le21psas.fsf@aartaka.me>
[-- Attachment #1: Type: text/plain, Size: 2282 bytes --]
>I've compiled a generic collection of data-checking macros (which I'm
consider contributing as SRFI), but I'm not satisfied with their
performance. Dave Thompson's blog post shows benefits from adding type
predicates before the code, but it seems that my approach of adding
assert-s to the start of the function is less effective and adds a lot
of performance overhead.
Is it this one: https://dthompson.us/posts/optimizing-guile-scheme.html?
An example demonstrating the overhead could be useful to determine how to improve things.
>Thus the question: is there any way to declare types that Guile will
accept and act on? Especially if this way it exported for user to play
with. I haven't found any pointers in the manual, thus I'm asking it
here (I'm also asking it on the devel list because devs are more likely
to know the ins and outs of typing and maybe even able to act on it.)
The way to ‘declare’ it is to add those asserts or equivalent. The reason that there is no more about it in the manual is that currently there is not more to it than that.
I do think some support in Guile for type declaration could be useful, however.
For example:
(define (foo x y z)
[type declarations]
[do stuff with x y z])
could perhaps be translated into:
(define (foo-error1 x y z) [...]) ; ← raises some type error
(define (foo-error2 x y z) [...]) ; ← raises some type error
(define (foo-actual x y z)
[do stuff with x y z, and let compiler / optimiser assume the types are correct])
(define (foo x y z) ; this one the compiler should attempt to inline
(cond
([typecheck1 fails on x y z] (foo-error1 x y z))
([typecheck2 fails on x y z] (foo-error2 x y z))
(#true (foo-actual x y z))))
That way, external code using ‘foo’ can perhaps have the typechecks eliminated at compile time (without having to inline ‘foo-actual’). Or if not all typechecks could be eliminated but most typechecks are repeated (for example because ‘foo’ is called in a loop with shared values of x and y), then some typechecks could be moved to the front and the code ‘foo-error1’ and ‘foo-error2’ for constructing the condition object (and raising it) doesn’t need to be duplicated ...
Best regards,
Maxime Devos
[-- Attachment #2: Type: text/html, Size: 4618 bytes --]
next prev parent reply other threads:[~2024-07-21 17:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 10:03 Type declarations and data validation utils? Artyom Bologov
2024-07-21 17:13 ` Maxime Devos [this message]
2024-07-21 23:26 ` Artyom Bologov
-- strict thread matches above, loose matches on Subject: below --
2024-07-20 23:10 Artyom Bologov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240721191330.qHDW2C0040wtc8B01HDWpb@laurent.telenet-ops.be \
--to=maximedevos@telenet.be \
--cc=guile-devel@gnu.org \
--cc=mail@aartaka.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).