On Thu, Apr 7, 2011 at 2:05 PM, Boyko Bantchev <[email protected]> wrote:
> The type of the initial and result values really does not need to
> have anything to do with the type of the list elements.  A typical
> example is the function
>        length = foldl (\n _ -> 1+n) 0
> which finds the length of a list: the initial and result values are
> integers, and the list elements can be of any type whatsoever.

That was what I thought.

> But I don't see a connection between this fact and the use of
> monads.  (Monads are a purely functional device for uniform handling
> of computations that, presumably, do not fit well in the purely
> functional style.)

J has / instead of foldr, and all the elements of an list have to have
the same type.

In other words, you treat J's / like Haskell's foldr if you use
something like a haskel monad to arrange for the types of all the
elements of the list to be consistent.

> I also do not understand what are the issues mentioned in the initial
> post.  Is it something related to list lengths, or types, or ...?

I am thinking that we should get this monad issue behind us first,
before we try to revisit my impressions from that original post?

(That said, it seemed to me that the length issue was directly related
to this concept of treating the initial element for a fold as outside
the list being folded.  If it had been in the list to start out with
there would have been no length issue.)

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

Reply via email to