Ricardo Wurmus <rek...@elephly.net> skribis: > Ludovic Courtès <l...@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’.