[Haskell-cafe] Learning Haskell

Tomasz Zielonka tomasz.zielonka at gmail.com
Tue Dec 6 15:07:31 EST 2005

On Mon, Dec 05, 2005 at 09:08:32PM -0500, Cale Gibbard wrote:
> To your second question, I'd say that Haskell isn't bad at small
> things. One can write a great deal of useful one-or-two-line Haskell
> programs. I'd consider its use in shell-scripting like tasks perhaps a
> little bit odd, but not really awkward at all.

For me, it isn't odd at all. I often face the some problem with
traditional shell scripting using tools like awk, cut, head, tail, sort,
etc - these tools are most often used in a way that is very sensitive
to formats of processed (text) files. This is a dangerous kind of
sensitivity, which often results in silent errors.

On the other hand in Haskell, with use of libraries like Parsec, it
is very easy to create a precise parser for the intended file format.
Almost every divergence from the assumed format will cause the program
to fail with a nice error message pointing to the problem.

Of course you can do similar things with regular expression provided
by tools like awk, sed and perl, but regexps don't scale to more
complicated formats (regular languages vs. context-free languages).

> Haskell code is generally pretty fun to write, there's usually not a
> lot of framework cruft that you need to write to get started on code
> that works.

Some Haskell libraries, like Parsec, require a bit of constant
boilerplate code to use - but you can write your own library
to move some of boilerplate code to one place. Recently, I was
very happy when I realized that I could reduce most of my small
Parsec-using programs by 5-10 lines of code this way.

If you wonder what kind of functions are these, below are their
signatures. I would have to ask my boss to show the actual code, but
they are really quite simple, and the types tell everything.

    parseFile :: CharParser () a -> FilePath -> IO a
    parseStdIn :: CharParser () a -> IO a

    parseOrFail :: Monad m => GenParser tok () a -> SourceName -> [tok] -> m a

    lazyMany :: CharParser () a -> SourceName -> [Char] -> [a]
    parserToMaybeFun :: GenParser tok () a -> ([tok] -> Maybe (a, [tok]))

    parseWithText :: CharParser st a -> CharParser st (a, String)

With these some programs become really simple:

    import ...

    main = do
        x <- parseStdIn fileParser
        do something with x

    fileParser = do

Best regards

I am searching for a programmer who is good at least in some of
[Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland

More information about the Haskell-Cafe mailing list