From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian Price Newsgroups: gmane.lisp.guile.user Subject: Re: prompts: any example ? Date: Wed, 07 Mar 2012 12:54:02 +0000 Message-ID: <871up4zi51.fsf@Kagami.home> References: <878vjiayzb.fsf@Kagami.home> <87r4x967by.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1331124879 17608 80.91.229.3 (7 Mar 2012 12:54:39 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 7 Mar 2012 12:54:39 +0000 (UTC) Cc: guile-user@gnu.org To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Mar 07 13:54:36 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S5GO4-0001GQ-1l for guile-user@m.gmane.org; Wed, 07 Mar 2012 13:54:36 +0100 Original-Received: from localhost ([::1]:33664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5GO3-0001cI-Dw for guile-user@m.gmane.org; Wed, 07 Mar 2012 07:54:35 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:46661) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5GNs-0001bc-HZ for guile-user@gnu.org; Wed, 07 Mar 2012 07:54:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S5GNi-0004pY-GI for guile-user@gnu.org; Wed, 07 Mar 2012 07:54:24 -0500 Original-Received: from mail-ww0-f49.google.com ([74.125.82.49]:56856) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5GNi-0004l5-4p; Wed, 07 Mar 2012 07:54:14 -0500 Original-Received: by wgbdr1 with SMTP id dr1so3245180wgb.30 for ; Wed, 07 Mar 2012 04:54:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; bh=c4tWwwMqEjwyEVU+8SUTRUcZFeoiedWTpVVFT+0g8e0=; b=vSmJ8zgX2bKQWynXpX24BJqVkMll6KfgJY52Zei4qLZ9W/ELSJNGm/lYkh432XJ/9G EM9J7k16J/GQ5P9p2sBWGXcvVx3qMXjn9YAJrupF6zQMorWk0PzT5c6Lrlbd7iEuvNaI krfwj2viT/pSp+3eTSgasbjnsUYn+sTqkmm3CGPFcTTHsujxRQqLiMA9FLLi/xKYRSZq fUjOjRyD/zvZ0YBkmp9ZcEkegEu5GrKiC+kSXhMPHdGVLDpeuCYAnzoBw12WjO6OlYpu YLQIrHVTzugM13NsAy5pTdcMGPhGMrnCIEhRmuPxj3ozUReFsGl7RiGYUuLi5DTmYcOl sPag== Original-Received: by 10.180.95.197 with SMTP id dm5mr15205768wib.20.1331124850468; Wed, 07 Mar 2012 04:54:10 -0800 (PST) Original-Received: from Kagami.home (host86-180-107-0.range86-180.btcentralplus.com. [86.180.107.0]) by mx.google.com with ESMTPS id d7sm94808765wiz.6.2012.03.07.04.54.07 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 07 Mar 2012 04:54:08 -0800 (PST) In-Reply-To: <87r4x967by.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Sat, 03 Mar 2012 16:18:57 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.49 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9319 Archived-At: ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Hi Ian, > > Excellent illustration, thank you! > > Ian Price skribis: > >> https://gist.github.com/1548531 - monadic reflection > > Could you expound on this one? I can feel the greatness, but I don=E2=80= =99t > fully grasp it. :-) Yes, and it doesn't help that it is missing a bunch of helpers :) I no longer have the original file, so I can't even remember if I stomped out the bugs in it(probably not). The trick comes from, I think, Filinski's "Representing Monads", although it has been quite a while since I've read it. Instead of monads being represented by the usual 'bind' and 'unit' functions, or the (categorical?) definition of 'unit', 'fmap', 'join', they are instead represented by two operators 'reflect' and 'reify'.=20 reify : (() -> a) -> m a reflect : m a -> a reify takes a function that returns a value, and returns a monadic value i.e. it lifts a pure expression to an effectful one. reflect takes a monadic value and returns the value. i.e. it lowers the effectful value into the pure layer. This representation has two nice properties. Firstly, we get direct style back :-). This one is important to me, and reflects the fundamental reason why we need continuations: To rescue us from the horror of forced styles :). The second one, which I don't think he mentioned in that paper (maybe in "representing layered monads"?) is that tagged delimited continuations actually allow us to use multiple monads quite naturally, without the need to invent things like monad transformers. In that example, I quite naturally mix the reader and state monads. It isn't quite perfect: the 'do-rename' function is not pretty, some functions like 'with-extended-environment' need to take a thunk, and without inference we need a different named reflect/reify for each monad, but it seems relatively useful and I was quite obsessed with it for a time. --=20 Ian Price "Programming is like pinball. The reward for doing it well is the opportunity to do it again" - from "The Wizardy Compiled"