On Wed, 9 Jun 1999, Friedrich Dominicus wrote:
[snip]
> What's a HOF?
>
A Higher Order Function, the key to code reuse and abstraction.
> > that first splits something up to a list using splitFn
> > (or with the generalization I mentioned, to a monad), then maps a
> > function over that list (namely beforeMap, because it's mapped
> > *before* the filter), filters something out (using the filterPredicate),
> > then again maps a function (namely afterMap, because it's mapped
> > *after* the filter), then somehow joins the list (or monad), using
> > unSplitFn.
>
> I would like names which tell me what is done.
>
> I read in contents of a file
> I process it, I build a string ...
>
> etc
>
Sounds fine, and the translation to haskell is very natural:
main :: IO()
main = do contents <- readFile filename
putStr (process contents)
process :: String -> String
..
> > numberStrPair2String
> > more accurately.
>
> why not build_number_string_pair?
>
because it does not build a number-string pair, it builds a string (from a
number-string pair).
> Sorry I havn't the Signature of Show in my mind bu of course it just
> builds a string.
>
If you know what it is doing it is easy to figure out the type.
Ok, so it takes something and converts it to a string - aha, the type must
be
a -> String
> > 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 ...
If you just want to read stdin and write to stdout - use interact, if you
whant to read a file - use readFile, if you want to write to a file - use
writeFile. What is the problem? I think you are making it harder than it
is.
/Lars L