foldr has two variants

foldr  f a l   :: function initial list
foldr1 f l     :: function list

So e.g. the following are the same

    +/ 10,~1+i.10
65

Prelude> foldr (+) 10 [1..10]
65


I don't exactly understand what you mean by different types.
The initial elem type has to be of the same type as an element of the list i.o. 
to apply
    f <initial element> <element of the list>

I.o.w. in Haskell you get

Prelude> (+) (8::Int)  (8::Integer)

<interactive>:1:15:
     Couldn't match expected type `Int' against inferred type `Integer'
     In the second argument of `(+)', namely `(8 :: Integer)'
     In the expression: (+) (8 :: Int) (8 :: Integer)
     In the definition of `it': it = (+) (8 :: Int) (8 :: Integer)



The following 'scans' are equivalent

scanl1 f l <==> f/\ l

scanl f a l <==> f/\ a,l




Hallo Raul Miller, je schreef op 07-04-11 16:41:
> Food for thought:
>
> J's / is different from Haskell's foldr in that Haskell's foldr allows
> you to specify an "initial element" which is independent of the rest
> of the list.
>
> 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).
>
> But this design apparently comes with a cost:  The result of scan
> (which seems to correspond to J's /\) apparently needs to be one
> longer than the argument list.
>
> http://conal.net/blog/posts/composable-parallel-scanning/
>
> Or at least.. that was how I interpreted him, though I am sure that
> someone with intimate familiarity with Haskell would instead point at
> some underlying rule that leads to both of these consequences (the
> design of foldr and the design of scan).  And, from that point of
> view, I imagine you could say that these two issues are only
> coincidentally related.
>

-- 
Met vriendelijke groet,
=@@i

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

Reply via email to