Sorry, should have sent it also to chatforum. Whatever complex initial argument you want to start with, applying f on initial element and an element of the list should be on the same types, e.g.
Prelude> foldl (\(x,y) e -> (y,x+e)) (0,2) [1..5] (8,9) Here the initial element argument is typed (a,a) and the list is typed [a] The result is typed (a,a) Note: a means same type. If not, I do not follow you. Please give an example. Hallo Raul Miller, je schreef op 07-04-11 18:15: > On Thu, Apr 7, 2011 at 11:58 AM, Aai<[email protected]> wrote: >> 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> > Really? for foldr? > > Consider this J example: > > M=: 20$0 > foldr=:1 :0 > : > X=.<x > Y=.y<@["u x > >u&.>/Y,X > ) > > M 4 :'1 x} y' foldr 2 3 5 7 11 13 17 19 > > Here, I have an initial value which is a different type from the > elements of the list. > > I can imagine that Haskell would require that the type of the result > of the function which is an argument to foldr would match the type of > the initial value (my x, here), but I do not see the point in > requiring that it match the type of items in the list. If that were > the case, I would think that it would be simpler and cleaner to > require that the initial value be a member of the list (which is what > J does). > -- Met vriendelijke groet, =@@i ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
