From: ludo@gnu.org (Ludovic Courtès)
To: Ricardo Wurmus <rekado@elephly.net>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: Templates for monadic procedures
Date: Wed, 03 May 2017 12:16:40 +0200 [thread overview]
Message-ID: <87k25yutx3.fsf@gnu.org> (raw)
In-Reply-To: <87d1bqh2xl.fsf@elephly.net> (Ricardo Wurmus's message of "Wed, 03 May 2017 08:25:42 +0200")
Ricardo Wurmus <rekado@elephly.net> skribis:
> Ludovic Courtès <ludo@gnu.org> writes:
>
>> So, <https://git.savannah.gnu.org/cgit/guix.git/commit/?id=dcb95c1fc936d74dfdf84b7e59eff66cb99c5a63>
>> adds a C++-inspired template mechanism to (guix monads). Now we can
>> write:
>>
>> (define-template (mapm monad proc lst)
>> …)
>>
>> That automatically leads to the definition of both a generic version
>> (same one as before, inefficient) as well as one specialized version for
>> each monad that is defined. Each specialized version is more efficient
>> because the monad it is specialized for is known at expansion-time, and
>> thus we can inline the monad’s bind/return:
> […]
>> All this relies on a “stateful macro” that keeps state across the
>> expansion-time and run-time stages. I think it’s a pretty fun hack!
>
> Wow! That’s very cool! I previously played with my own monads in Guile
> for a toy project and it bothered me that too many lookup happened at
> runtime. Having a lookup directory at expansion time is really neat,
> though I must say that this higher level macrology would be very hard
> for me to come up with from scratch!
>
> I wonder if we could also do monad type checking at expansion or compile
> time. That’s the last thing that’s missing here.
At this point we can distinguish between “definitely a monad” and “don’t
know” for the first argument of ‘mlet’ and the templated procedures.
That’s a start. ;-)
I really want to look at Turnstile, which uses macrology to introduce
some typing:
https://docs.racket-lang.org/turnstile/The_Turnstile_Guide.html
Ludo’.
prev parent reply other threads:[~2017-05-03 10:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-02 22:03 Templates for monadic procedures Ludovic Courtès
2017-05-03 6:25 ` Ricardo Wurmus
2017-05-03 10:16 ` Ludovic Courtès [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k25yutx3.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guix-devel@gnu.org \
--cc=rekado@elephly.net \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.