From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: Templates for monadic procedures Date: Wed, 03 May 2017 12:16:40 +0200 Message-ID: <87k25yutx3.fsf@gnu.org> References: <87shkmyl01.fsf@gnu.org> <87d1bqh2xl.fsf@elephly.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5rKv-0002s7-Ta for guix-devel@gnu.org; Wed, 03 May 2017 06:16:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d5rKs-000690-P5 for guix-devel@gnu.org; Wed, 03 May 2017 06:16:45 -0400 In-Reply-To: <87d1bqh2xl.fsf@elephly.net> (Ricardo Wurmus's message of "Wed, 03 May 2017 08:25:42 +0200") 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: Ricardo Wurmus Cc: guix-devel Ricardo Wurmus skribis: > Ludovic Court=C3=A8s writes: > >> So, >> adds a C++-inspired template mechanism to (guix monads). Now we can >> write: >> >> (define-template (mapm monad proc lst) >> =E2=80=A6) >> >> 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=E2=80=99s bind/return: > [=E2=80=A6] >> All this relies on a =E2=80=9Cstateful macro=E2=80=9D that keeps state a= cross the >> expansion-time and run-time stages. I think it=E2=80=99s a pretty fun h= ack! > > Wow! That=E2=80=99s very cool! I previously played with my own monads i= n 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=E2=80=99s the last thing that=E2=80=99s missing here. At this point we can distinguish between =E2=80=9Cdefinitely a monad=E2=80= =9D and =E2=80=9Cdon=E2=80=99t know=E2=80=9D for the first argument of =E2=80=98mlet=E2=80=99 and the temp= lated procedures. That=E2=80=99s 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=E2=80=99.