<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<body bgcolor="#ffffff" text="#000000">
I've seen the analogy with "recipes" used before, but I think that you
need to be careful when you try to distinguish the analogy to monads
from the analogy to functions. The reason is that, in the one-of-many
ways that I view monads, a monad is just a high-order <i>function </i>that
abstracts away function composition. In particular, if I have an
action f, and an action g, I can think of them as recipes,
because I can combine them via f >>= g. It's only after I
combine all of
my actions together that I apply the result to my input (via "run").<br>
Well, that's just like function composition. In particular, if I have
a function f, and a function g, I can think of them as recipes,
because I can combine them via f . g. It's only after I combine all of
my functions together that I apply the result to my input.<br>
Sebastian Sylvan wrote:
<pre wrap="">On 14/08/07, Dan Piponi <a class="moz-txt-link-rfc2396E" href="mailto:email@example.com"><firstname.lastname@example.org></a> wrote:
<pre wrap="">On 8/14/07, Sebastian Sylvan <a class="moz-txt-link-rfc2396E" href="mailto:email@example.com"><firstname.lastname@example.org></a> wrote:
<pre wrap="">Well that's easy, don't use the recipe analogy to explain code, use it
for monadic values exclusively, and you avoid the confusion entirely!
I don't think it's that complicated.
<pre wrap="">It certainly is complicated. I think I have a good grasp of monads to
the point where I can tease novel monads (and comonads) out from
algorithms that people previously didn't see as monadic. And yet I
still don't understand what you are saying (except with respect to one
specific monad, IO, where I can interpret 'action' as meaning an I/O
<pre wrap="">Monads have a monadic type. They
represent an abstract form of an "action", which can be viewed as an
analogy to real-world cooking recipes.
<pre wrap="">All functions can be viewed as recipes. (+) is a recipe. Give me some
ingredients (two numbers) and I'll use (+) to give you back their sum.
No, (+) is a function, not a "recipe". Again, you're introducing
confusion because you use the same analogy for two *different* things.
Use it for one of the things and you don't have that problem.
I want to use "recipe" to mean "an abstraction for an action". It
could litterally be a text string containing the C code required to do
a particular IO action, for example. (+) isn't an abstraction in the
same sense, it *is* the "action" itself. (+) is the actual value of
the function that will add two numbers together. A monadic value is an
abstract recipe that you can't actually use directly (you can only
combine them, and if you're lucky you can "perform" them once you're
done combining them, e.g. ST, but not IO).
<pre wrap="">As long as you don't
deliberately confuse things by using the same analogy for two
different things I don't see where confusion would set in.
<pre wrap="">If I was one of your students and you said that monads are recipes I
would immediately ask you where the monads are in my factorial program
regardless of whether you had introduced one or two different
analogies for recipes.
Why would you? I really don't see where you would get that idea? If I
tell you that a function returns "a fruit", would you ask where the
fruit in your factorial program is? Probably not. Why would you go off
and take an analogy for monads and apply it to something completely
different and still think the analogy holds?
A function is *not* a recipe in this analogy, it's just a function
(which you hopefully should've covered by the time you get to monads.
Monadic values, and *only* monadic values (not functions!) are to be
viewed as analogous to real world cooking recipes in this analogy.
Functions shouldn't. If you start mixing things together it will get
confused, so just don't!
I don't think this is very difficult to understand, so if you still
don't get it, I think you're just going to have to read it again
because I can't explain it any better, and in my experience, newbies
tend to understand this analogy within seconds (maybe that's the
problem, you're not a newbie)...