> >Yes you can define it, > > And you can, as well. Man sollte sich nicht darauf verlassen, daß ein Englander "man" verwendet, wenn es angebraucht wäre¹.
> That's how common idioms come into being; > there's no special magic about the folds already in existence. Well, my point is that there is -- indeed some ways of defining the type for lists use a fold as the starting point. I mentioned the lack here because I think there is some deeper structure that someone cleverer than me may be able to see. > > >It seems to me that there's something odd about the way the > >IO monad interacts with bulk operations on files. > > That may be more related to IO than to the monadic approach > to it Yes. Hence the change of subject line. > >In particular, it seems odd that getContents should ever be the > >easiest way of tackling something, > > Who says that? I did! I think getContents is a klugey hangover from stream based I/O, and the existence of "semi-closed handles" supports that, so I'm hoping that people might become interested in looking at the question. > >One of the great things about fold is that you don't have to > >code the test for the end: it's encapsulated in the > >higher-order function. Shouldn't there be the same for IO? > > Isn't it? > > getContents = foldX (++) "" -- we drop the newlines here.. > getLines = foldX (:) [] > > No eof-testing in sight. Sure, once we've defined foldX, but then we need to know whether it really is a fold &c. I should remember to make my messages to the list less indirect. > So we've mostly got a fold lifted into the io-monad, with getLine > delivering the "head" (and implicitly truncating further input to > the "tail"). What more do you want?-) Theory! That's what I want! Cheers, Jón 1. I had to get help with this; perhaps it would have been better to leave my numerous mistakes in it! -- Jón Fairbairn [EMAIL PROTECTED] 31 Chalmers Road [EMAIL PROTECTED] Cambridge CB1 3SZ +44 1223 570179 (after 14:00 only, please!) _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell