On 3 January 2012 08:46,  <googlegro...@khinsen.fastmail.net> wrote:
> Dragan R writes:
>
>  > On the net I read that "Impure functional programming doesn't really
>  > need monads."
>  > and "It appears that in the presence of mutable state, a lot of the
>  > advantages of monads become moot."
>
> Monads are an abstraction mechanism, so you never need them. You can
> always use the lower-level techniques in terms of which monads are
> implemented.

This +1.

You need to be more specific about what you mean when you say code
"uses monads". In one sense, any code which uses a 'for' sequence
comprehension is using a monad, because it satisfies all of the
properties of a monad. In another sense, only code which contains and
names specific things as monads, and uses general operators which
apply to all monads, is using them.

I've been using monads a lot recently with Overtone -- by which I mean
I've been using (state-t cont-m), the continuation monad transformed
to add state. I'm using it because: a) I want to simulate state
representing the current beat number, and b) I want to schedule future
events using apply-at; so rather than returning from a function to
continue a melody, I call apply-at and pass the current continuation
to it.

As an example of what I've achieved, see this gist:

https://gist.github.com/1441831

Using clojure.algo.monads, I have created a basic DSL which allows me
to say (wait 1) to pause for one beat, and (at-current-beat (foo)) to
schedule event (foo) to happen on the current beat. These commands are
relative to the current time, but using monads I can transform them
into commands at an absolute time using overtone's built-in 'at and
'apply-at macros, and to automagically handle the scheduling.

This is a work in progress; I'm planning a fuller write-up of what I'm
doing which I will send to the overtone list once I've ironed out the
wrinkles.

Phil

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to