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: Thu, 08 Mar 2012 18:27:15 +0000 Message-ID: <87wr6vx81o.fsf@Kagami.home> References: <878vjiayzb.fsf@Kagami.home> <87r4x967by.fsf@gnu.org> <871up4zi51.fsf@Kagami.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1331231254 26759 80.91.229.3 (8 Mar 2012 18:27:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 8 Mar 2012 18:27:34 +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 Thu Mar 08 19:27:33 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 1S5i3o-0003hi-TA for guile-user@m.gmane.org; Thu, 08 Mar 2012 19:27:33 +0100 Original-Received: from localhost ([::1]:48751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5i3n-00068k-Vz for guile-user@m.gmane.org; Thu, 08 Mar 2012 13:27:31 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:36101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5i3j-00068e-KM for guile-user@gnu.org; Thu, 08 Mar 2012 13:27:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S5i3h-00020d-SY for guile-user@gnu.org; Thu, 08 Mar 2012 13:27:27 -0500 Original-Received: from mail-ww0-f41.google.com ([74.125.82.41]:45190) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5i3h-00020M-Fz; Thu, 08 Mar 2012 13:27:25 -0500 Original-Received: by wgbds1 with SMTP id ds1so1668321wgb.0 for ; Thu, 08 Mar 2012 10:27:22 -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; bh=xHXtvkAJwhDIsh6JcwHmoX+oEqSgHBbb0LHqStCsR0Y=; b=K3yJqO/UL9IZU5uRGDv+oZt8hXxUqsd1RBBPpnshFbYawEoO2BKktH/Kg5vzKV3pnh V3xhW1NG7rnjO+kqOxML0SvrVK/+FBOVYWTZy+nDp3nW2auSj/Sn+xHxHU5scqPBnZVF fAkyJvD2T3LEaZtEBXsZCjz9adqxAw4DM1L5Pup3kfvHWMdZiWUeZLBcZP+zaCSiJXjC 9nO8Mg6diyFdeGBPA8YNDDso/G0M/DzuSL0f+79g74QvaJ42L2MmQ89DJBW4UT8Cw9ej sUjPnDIYGkLzSEVDav29PqQuSomaYA7+9xtQjH1tJu+YKHip8VFQ0jTEvGWGKQ+u/A2S sdnw== Original-Received: by 10.180.83.97 with SMTP id p1mr15024140wiy.19.1331231242161; Thu, 08 Mar 2012 10:27:22 -0800 (PST) Original-Received: from Kagami.home (host86-149-109-182.range86-149.btcentralplus.com. [86.149.109.182]) by mx.google.com with ESMTPS id w14sm33107611wiv.11.2012.03.08.10.27.20 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 08 Mar 2012 10:27:21 -0800 (PST) In-Reply-To: <871up4zi51.fsf@Kagami.home> (Ian Price's message of "Wed, 07 Mar 2012 12:54:02 +0000") 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.41 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:9326 Archived-At: Ian Price writes: > 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'. > > 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. One thing I forgot to mention is that there is a simple way to turn the unit/bind representation into the reify/reflect representation, and you see it at the top of the gist. (define (reify thunk) (reset (return (thunk)))) (define (reflect m) (shift k (>>= m k))) only I used tagged variants of shift/reset instead to allow mixing (as already mentioned) -- Ian Price "Programming is like pinball. The reward for doing it well is the opportunity to do it again" - from "The Wizardy Compiled"