6

When I think of the word 'computation' - my mind jumps to lambda calculus or operations on a state machine representing a CPU. It is quite a broad definition.

Now some people talk about monads as 'representing a unit of a computation'.

But if we consider the identity monad - this is a 'reference to the computation'. But ultimately we're almost certainly talking about functional programming. We're using functions. We use functions to transform data. So where does this fancy language come from?

My question is: When we say a monad 'encapsulates a computation' - is this just saying 'wraps a functional transformation of data'?

hawkeye
  • 4,819
  • 3
  • 24
  • 35
  • 1
    The monad by itself just "wraps" the data, but monad composition offers the transformation. These 2 facts may be used and in fact used to encapsulate the computation inside the transformation. But in general, the monad is not about wrapping the computations. – paul Dec 10 '14 at 11:21
  • Great - could you expand that into an answer? – hawkeye Dec 11 '14 at 07:27
  • Terminology questions are most hard to answer, I suppose. I can only use general reasoning here. The direct question is about "what we are saying", and I have no direct answer to this. But we can disscuss the topic though. – paul Dec 12 '14 at 11:22
  • Lambda calculus has no "data flow" allegory, but has data transformation. Imperative world hasn't data flow either, but has computation flow. Monadic way combines both of the best of two worlds: data transformation and explicit computation (order). And we can say "given monads encapsulates a computation". – paul Dec 12 '14 at 11:26
  • Great - could you put that down as an answer? (Rather than a comment) – hawkeye Dec 12 '14 at 19:11
  • I'm afraid the keyword is **represent**, and the *substance* just doesn't matter. Monad *is* monad because they are composable, and that their composition must obey a few prescribed rules. In this way you could say Lego blocks is a kind of monad. – rwong Dec 14 '14 at 09:56
  • @paul: "The monad by itself just "wraps" the data, but monad composition offers the transformation. These 2 facts may be used and in fact used to encapsulate the computation inside the transformation. But in general, the monad is not about wrapping the computations.": Could you expand on this in your answer? – Giorgio Dec 14 '14 at 13:42

1 Answers1

3

Lambda calculus has no "data flow" allegory, but has data transformation. Imperative world hasn't data flow either, but has computation flow. Monadic way combines both of the best of two worlds: data transformation and explicit computation (order). And we can say "given monads encapsulates a computation"

paul
  • 176
  • 2
  • Imperative world is dominated by control-flow thinking, but to say that it doesn't have data-flow is a bit of a stretch. I would say that given imperative code, one could derive theories that would describe the data-flow of the code when it is executed in a real machine. One even has the choice of doing this analysis without execution (static analysis), or with (during) execution (dynamic). Many short fragments of imperative code can be transformed into SSA which would have revealed the data-flow. – rwong Dec 14 '14 at 10:04
  • Well, "short" is right word here. And you can write a rather big program with obvious data flow, or, even, you can transform any given imperative program to functional form (with IO limitations) and thus get data flow. But "real" data flow will hidden in. Good analogy here -- when you imitate Peano ariphmetic in lambda and build your program on top of it, your real calculations will be hidden in gazillion function calls. – paul Dec 16 '14 at 19:52