guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Templates for monadic procedures


From: Ricardo Wurmus
Subject: Re: Templates for monadic procedures
Date: Wed, 03 May 2017 08:25:42 +0200
User-agent: mu4e 0.9.18; emacs 25.1.1

Ludovic Courtès <address@hidden> 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.

> Currently it doesn’t have a noticeable performance impact because monads
> are used sparsely, but I expect it will help with the
> ‘wip-build-systems-gexp’ branch, which aims to use gexps (and thus
> ‘%store-monad’) for packages.

Yay, super cool!  I’m looking forward to seeing that branch merged!

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net




reply via email to

[Prev in Thread] Current Thread [Next in Thread]