Yes, I see. I'm going to guess that the parser-m that I give above has no possible m-zero, so I think I'll have to rethink how I'm going to approach this problem. I probably am going to just define failure in another way. (The reason why I can't use nil is because I need to store metadata on the object representing failure. I'm sure I'll figure something out.) Thanks for your help.
On Nov 22, 1:31 pm, jim <jim.d...@gmail.com> wrote: > Samppi, > > Good work on figuring that out. It's by working through those kinds of > problems that you really learn about monads. It is indeed the case > that not all monads have m-zero and m-plus defined for them. The state- > m monad is one of those. Not only that, but if you take a look at the > state-t monad transformer, you'll see m-zero defined like this: > > m-zero (with-monad m > (if (= ::undefined m-zero) > ::undefined > (fn [s] > m-zero))) > > Notice that when you combine the state-m monad with another monad > using state-t, an m-zero for the resulting monad is only defined if > the original monad had an m-zero. Also notice that when an m-zero is > defined for the original monad, the new m-zero is a function that > accepts a state and returns the original m-zero without regard to the > state that was passed in. And that's where your original monad ran > into problems, you tried to make the new m-zero's return value > dependent on the state that was passed in. > > Furthermore, it's hard to see it, but :when clauses in domonad require > that m-zero exists, and obeys the monad laws for zero and plus. So if > you're m-zero is incorrect, :when clauses won't work either. > > At this point, you need to drop back and understand exactly what > you're trying to accomplish and make sure you really understand monads > as fully as possible. I just spent almost 2 weeks working on my own > monad for writing web applications. I finally gave up and sat down to > really learn how the continuation monad works. After that, I > discovered I could use it instead of writing my own and it turned out > to be very easy. Very often, you can come up with something that > almost works and think that it just needs one more tweak to get it > right. That's what happened to me and I wasted a lot of effort before > I finally tossed it out and really focused on understanding. > > If you'd like to post details of what you're doing, I'd guess some > folks would lend some assistance. > > Jim > > On Nov 22, 11:04 am, samppi <rbysam...@gmail.com> wrote: > > > > > Thanks for the help. > > > After working it out, I just figured out that the reason why the > > second axiom isn't fulfilled by the m-zero above is this part in m- > > bind: > > ((product-fn product) new-state)))))) > > > product-fn, which in the second axiom's case is (fn [x] m-zero), gets > > called and becomes m-zero, which is in turn called on new-state, not > > the old state. > > > I cannot figure out at all, though, what m-zero *is* valid under both > > axioms. Now I don't see how it's simply possible at all—are there > > monads for which there is no value of m-zero, and is this one of them? > > > On Nov 21, 9:02 pm, jim <jim.d...@gmail.com> wrote: > > > > Glad you found that tutorial useful. I had to run this morning, so I > > > couldn't really reply. I'll try to read your post more closely > > > tomorrow and see if I can offer any useful insight. > > > > Jim -- 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