It would be nice if the prelude defined more general functions like: > splitStr c s = left:case right of [] -> []; otherwise -> splitStr c (tail right) > where (left,right)=span (/=c) s > joinStr c l = case l of []-> []; otherwise -> foldl1 (\x y->x++c:y) l The implementation of lines and unlines with these is trivial. Sven's code becomes: > longlines minlen filename = > readFile filename >>= > splitStr '\n' .| filter (\x->length x>=minlen) .| joinStr '\n' .| putStr -Alex- ___________________________________________________________________ S. Alexander Jacobson Shop.Com 1-212-697-0184 voice The Easiest Way To Shop On Tue, 1 Jun 1999, Sven Panne wrote: > Hannah Schroeter wrote: > > [...] So, still no need to fuzz with file handles :-) > > ... and no need to fuzz with intermediate names, either. :-) If you > define an operator for reversed function composition > > (.|) = flip (.) > > and read it like a pipe in *nix, you get a one-liner: > > longerThan fn lenlim = readFile fn >>= lines .| filter (length .| (>lenlim)) .| >unlines .| putStr > > Whether this is more or less readable than Hannah's version is largely > a matter of personal taste. > > Cheers, > Sven > -- > Sven Panne Tel.: +49/89/2178-2235 > LMU, Institut fuer Informatik FAX : +49/89/2178-2211 > LFE Programmier- und Modellierungssprachen Oettingenstr. 67 > mailto:[EMAIL PROTECTED] D-80538 Muenchen > http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne >
Re: how to write a simple cat
S. Alexander Jacobson Tue, 1 Jun 1999 10:27:13 -0400 (Eastern Daylight Time)
- how to write a simple cat Friedrich Dominicus
- Re: how to write a simple cat Hannah Schroeter
- Re: how to write a simple cat David Overton
- Re: how to write a simple cat Keith Wansbrough
- Re: how to write a simple cat Friedrich Dominicus
- Re: how to write a simple cat Hannah Schroeter
- Re: how to write a simple cat Friedrich Dominicus
- Re: how to write a simple cat Hannah Schroeter
- Re: how to write a simple cat Sven Panne
- Re: how to write a simple cat Friedrich Dominicus
- Re: how to write a simple cat S. Alexander Jacobson
- Re: how to write a simple cat Sven Panne
- Re: how to write a simple cat Friedrich Dominicus
- Re: how to write a simple cat Jan Skibinski
- Re: how to write a simple cat Lars Henrik Mathiesen
- Re: how to write a simple cat Keith Wansbrough
- Re: how to write a simple cat Lennart Augustsson
- Re: how to write a simple cat Kevin Atkinson
- RE: how to write a simple cat Frank A. Christoph
- Re: how to write a simple cat Friedrich Dominicus
- RE: how to write a simple cat Simon Peyton-Jones