At 16:37 Uhr +0200 09.06.1999, Friedrich Dominicus wrote:
> > I think exercise with the purely functional, non-I/O core (and perhaps
> > interact like someone else suggested) teaches you the mode of
> > thinking in purely functional languages. That thinking can also
> > help you understand the way I/O is implemented in a referentially
> > transparent way.
>
>I disagree, small scripts spend most of the time doing I/O if I don't
>understand how to do that I'm not able to even write the most simple
>things. This is eg. true for my cat ...
I disagree. You need to know more about Functional Programming
(and also the Haskell type system and its IO system) before
you should try to solve your problems. It's like you want
to drive without knowing anything about the engine, brakes, ...
There are many great introductory books which would
give you an idea about some of the basic building blocks
of "functional" software development. I don't think
"Haskell" is the problem - it's the way of thinking - you
need to "unlearn" previous knowledge about coding
algorithms. For your pleasure ;-) , lazy FP code in Lisp:
(defun longerThan (filename lenlim)
(series:iterate ((l (series:choose-if
(lambda (l) (> (length l) lenlim))
(series:scan-file filename #'read-line))))
(print l)))
Which is really similar in spirit to Hannah Schroeter's:
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 think both versions are really simple to write.
Rainer Joswig, "Lavielle" EDV Systemberatung GmbH & Co. KG, Lotharstrasse 2b,
D22041 Hamburg, Tel: +49 40 658088, Fax: +49 40 65808-202,
Email: [EMAIL PROTECTED] , WWW: http://www.lavielle.de/