Hannah Schroeter wrote:
> 
> Hello!
> 
> On Tue, Jun 01, 1999 at 06:58:32AM +0200, Friedrich Dominicus wrote:
> > [...]
> 
> > I want to do the following, read a file line by line and finding out
> > which line is longer than x-chars. I want to print out which lines are
> > so long. I think that can just be done line-wise.
> 
> > Thanks for you answer I hope I got it right with that information.
> 
> longerThan :: String {- filename -} -> Int {- length limit -} -> IO ()
> longerThan fn lenlim = do
>     content <- readFile fn
>     let li = lines content
>         fl = filter (\l -> length l > lenlim) li
>     putStr (unlines fl)

I want to try if I got it right. You're using lazy evaluation here with
readFile, is that correct? So after I read in a chunk form that file
into one large String, lines splits that line on a '\n' position. The
lines li are filtered and l is one line a String-List which is added to
fl all the filterd lines are then put back into on large String. Uff. Is
that nearly correct?


Sometimes I've got the feeling that Haskell drives me nuts. I really
have a hard time to learn that, but somtimes I feel that this is the way
to go. But everytime I try to do I/O I've got the feeling as I had never
programmed before.


This solution is quite nice. I now have one extra question (maybe two
;-) How can I combine the output with a line-number can I put that into
the filter? Or do I have to found another solution?

Regards
Friedrich


Reply via email to