Actually, scan is a bad analogy for /\ in the first place.
J's \ is more like Haskell's inits
(http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-List.html#v:inits),
except that the Haskell version starts with the empty list (so really \ is
more like tail . inits)
So the proper analog to
+/\ 1 2 3
1 3 6
is something like
map (foldlr1 (+)) $ (tail . inits) [1, 2, 3]
[1, 3, 6]
Let's try with something more interesting than addition:
%/\ 1 2 3
1 0.5 1.5
map (foldr1 (/)) $ (tail . inits) [1, 2, 3]
[1.0,0.5,1.5]
Good.
"David Hotham" <[email protected]> wrote in message news:...
>I think you have a mistaken idea about what a (Haskell) monad is. At the
>start of this thread you wrote:
>
> "This means you can use Haskell's foldr with a function which combines
> arguments of two different types without having to write a Haskell
> Monad (which means: deriving a new function and type to let both of
> the function argument types be consistent with each other)."
>
> This isn't what a Haskell monad is at all.
>
> While I'm not quite sure what your point is, I think it unlikely that
> understanding Haskell monads will be relevant to it - so I won't go any
> further into that.
>
> On your original post, as best I understand it, I think that you may just
> have chosen the wrong Haskell analog for /\. You probably want one of the
> scan variants that treats the first element of the list as the seed. So
> for example:
>
> scanl1 (+) [1,2,3,4]
> [1,3,6,10]
>
> Does this help?
>
> David
>
>
>
> "Raul Miller" <[email protected]> wrote
> in message news:[email protected]...
> 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