> > 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?
> 
> Yes, filter applies the function parameter (in that case the lambda)
> to each element of the list parameter (2nd) to yield booleans, and
> returns a list of those elements of the original list, where the
> function yielded true.
> 
> > 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.
> 
> What is difficult is that by using some predefined function, one can
> express very much in very small code. I believe Haskell is even more
> expressive than most OO languages with comparable libraries
> (perhaps except Smalltalk, as that has also a very compact syntax).

I havn't made my mind if that is positive of negative. Sometimes it
remind me of Perl and I'm not a big lover from it.

> 
> Another difficulty is monadic I/O. Perhaps you should exercise
> programming with standard higher-order functions without I/O
> a bit more, so that you master that difficulty and don't have
> to *simultaneously* understand both the HOF things and I/O.

That might be good advice but I/O is one of the most essential things
and I have to know how to use it proper for writing small skripts. And
Yes I'll train on higher-order-functions. But that's not all I've to
lean not to having to use all the  parameters a function has. A good
example for this is IMO foldx (l,r)




> 
> Either look at the solutions with the "pipe" (.|) operator that
> have been posted. (I like them, btw :-) ). Or pre/postprocess the
> li/fl variables, depending on if you need the original line numbers
> or numbers for the generated lines.

I rewrote that sligthly to get it more in sync with the book I read they
are using >.> for it and I think I like it a bit better but reading it
as a pipe symbol is very helpful too.

> 
> In the latter case, you can do this:
>   let numbered_lines = zipWith (\lineno linecont ->
>                                   show lineno ++ "\t" ++ linecont)
>                                [1..]
>                                fl
>   putStr (unlines numbered_lines)
> instead of the original putStr "statement".
> 
> In the first case, you must attach line numbers to the original file
> contents. li is the list of lines.
>   let li' = zip [1..] li
> creates a list of pairs (line number, line content).
> 
> You must then adapt the filter function from \l -> ... to
> \(_linenumber, l) -> ..., to extract the line content from the
> (line number, content) pair.
> 
> For the final output, you must convert the remaining (number,content)
> pairs from fl to single strings containing the line number in textual
> form, i.e.
>   let fl' = map (\(number, content) -> show number ++ "\t" ++ content) fl
>   putStr (unlines fl')
>

This comments helped me. So I think I will put them under my pillow;-)

Regards and thanks
Friedrich


Reply via email to