Tracy Harms-3 wrote: > > Viktor Cerovski <[EMAIL PROTECTED]> wrote: > >> [I]n fact, monads are exactly >> the solution to the problem of how to introduce stateful >> functions (or, in other words, side-effects) into a pure-functional >> language. >> > > Taking tacit expression as a pure-functional portion of the J language, > how can > this solution be effected? For some weeks I've been trying, > unsuccessfully, to > envision J equivalents to Haskell's monads and arrows. > > It may be that because J is a multi-paradigm language there is no > possibility > of a parallel, but I don't find that idea plausible. The limited > functional > purity of J may make such solutions unattractive or awkward, but since > there is > a rather clear-cut range within which functional purity is maintained, my > guess > is that the technique you applaud can be accomplished in J. >
Current pure functional languages (like Haskel, ML, OPAL) have usually the following features: 1) No side-effects (which is what is traditionally, via recursive functions, identified with the functional programming). That's in J loosely: programming with $: and also, but not necessarily, tacit. M. is also functional since it does not introduce side-effects, it only caches results for their faster recomputation. 2) Types, typed lambda functions with polymorphism, inheritance, etc. It's like in OO languages, but as I'll mention in a moment, more and maximally general. 3) Currying and lazy evaluation (again, no such things in J: the closest, but still quite different, is n&v). 4) Mixfix notation (similar to defining functions via pattern-matching). Now, to get to monads we need 2) plus the ability to have mappings of types into types, which is mathematically possible in the category theory via functors. Monad is then a functor, a mapping of types into types, that has four operations: map, lift, flatten and & (a.k.a. sequence), satisfying certain axioms. I'll resort now to a caricature: a pair of functions gets "lifted" into the monad world of mappings of types, which is "flat" because there are no higher-order mappings than functors (that makes the category theory interesting in foundational problems in/of mathematics), and, there and then, & of the two functions mimics the good-old sequence of evaluations. This allows us to define state machines, counters, generators, objects, etc. all described functionally, without any side-effects, lazy evaluated, etc. I sketch this just to give some picture of why it would be quite a chore to get monads in J in their full glory. -- View this message in context: http://www.nabble.com/Functional-solutions-to-side-effect-dependencies-tp20746859s24193p20753872.html Sent from the J Programming mailing list archive at Nabble.com. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
