From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Templates for monadic procedures Date: Wed, 03 May 2017 08:25:42 +0200 Message-ID: <87d1bqh2xl.fsf@elephly.net> References: <87shkmyl01.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5njV-0005jS-Cg for guix-devel@gnu.org; Wed, 03 May 2017 02:25:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d5njU-0006VG-8c for guix-devel@gnu.org; Wed, 03 May 2017 02:25:53 -0400 In-reply-to: <87shkmyl01.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel Ludovic Courtès writes: > So, > 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