The first example:

Lift =: ]
Bind =: @

The three laws that a monadic process must satisfy are:

1) Left identity:     Lift Bind f      === f
2) Right identity:    f Bind Lift      === f
3) Associativity:    (f Bind g) Bind h === f Bind (g Bind h)

Let's check these (f, g and h are any three verbs):

1)   ] @ f  === f    NB. true.

2)   f @ ]  === f    NB. true *only* in the case of J-monadic application of
the verb f...@]

3)   (f @ g)@ h === f @(g @ h)   NB.  true.

Thus, any monadic verb (in the sense of J), built up from 
@ ,  ]  and any verbs is an instance of monadic (in the 
sense of Haskell) process.

The second example:

Lift1 =: [
Bind1 =: @

Notice that Lift,Bind on the one hand and Lift1,Bind1 on the 
other are two different monadic processes. For example:

process1 =: f...@g@]
process2 =: f...@g@[

would have been of different types if they had been
defined as monads in Haskell, for instance PipeFromRight
and PipeFromLeft.
 
That's where the type system becomes important, because
although process1 and process2 are both verbs in J, they 
indeed describe two different kinds of piping of data into the
processing pipeline (set up by f and g.)  

For those who want to have such fine distinctions made explicit, 
and/or to build up particular kinds of processes with precise type 
prescriptions of what enters/exits a process and how it is processed
in a purely functional setting, Haskell-like type system is the way 
to go.

Lift in these examples fulfills the role of the pipeline entrance 
point operation that prepares the data for entering into 
the pipeline.

-- 
View this message in context: 
http://old.nabble.com/Two-Examples-of-Haskell-like-Monadic-Processes-in-J-tp27211322s24193p27211322.html
Sent from the J Programming mailing list archive at Nabble.com.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to