A few more words on monads and their pertinence to /.

It is true that monads, in the sense of Haskell, are not merely a
tool for masking a value of some type as a value of another.  But
if one wishes so, that, too, is possible.

For example, in J, we can consider a boxed value a monad.
Technically, we would use the verb < (box) in place of Haskell's
`return', and the adverb @> -- agreeing that we always apply it to
a verb that produces a boxed value -- for Haskell's `=<<'.

E.g.
   rtn =. <
   lnk =. @>
   u =. rtn@(2x&^)
   v =. rtn@#@":
   u lnk rtn 15
+-----+
|32768|
+-----+
   v lnk u lnk rtn 15
+-+
|5|
+-+

Then, in terms of `rtn' and `lnk', we can define what Haskell
calls liftM2
(http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:liftM2)
which `lifts' any dyadic verb to one that operates on monadic values.
Thus, wherever we would have said
   f / a-list
we can say
   f liftM2 / a-list-of-boxed-items
where within the boxes there may live values of different shapes and
types.

Whether it is worth doing that through monads in J is another question
-- after all, boxing/unboxing is directly available, without the need
for abstracting in the form of monads.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to