guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: prompts: any example ?


From: Ian Price
Subject: Re: prompts: any example ?
Date: Wed, 07 Mar 2012 12:54:02 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

address@hidden (Ludovic Courtès) writes:

> Hi Ian,
>
> Excellent illustration, thank you!
>
> Ian Price <address@hidden> skribis:
>
>> https://gist.github.com/1548531 - monadic reflection
>
> Could you expound on this one?  I can feel the greatness, but I don’t
> 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'. 

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.

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]