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
> 




Reply via email to