Friedrich Dominicus wrote:

> 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.

Actually, you can do a lot without learning about I/O.  The function `interact'

converts a `String->String' function into an IO function which can be used
at the top level.  Here are some simple examples:

-- Just copy stdin to stdout
main = interact id

-- Remove all Q from stdin
main = interact (filter (/= 'Q'))

-- Print the line number in front of each line
main = interact (unlines . zipWith (\n l -> show n ++ " " ++ l)  [1..] . lines)

-- Print a sorted list of all words
import List
main = interact (unlines . nub . sort . concatMap words . lines)


Well, I'm sure you get the idea.

    -- Lennart




Reply via email to