[Top][All Lists]
[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: |
Thu, 08 Mar 2012 18:27:15 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) |
Ian Price <address@hidden> 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"