Ian Price <ianpric...@googlemail.com> 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"