[Haskell-beginners] clarity and complexity of Haskell code?

Brent Yorgey byorgey at seas.upenn.edu
Sun Sep 25 19:10:27 CEST 2011

On Sun, Sep 25, 2011 at 10:25:25AM -0500, Gregory Guthrie wrote:
> I always enjoy and tout the clarity and simplicity of the declarative style of functional programming, and with that also Haskell.
> But it seems that although the wonderfully short and clear examples dominate early learning and usage, the forums like this and café are dominated by examples more like this:
>      import Data.Enumerator (run_, ($$), (=$))
>      import Data.Enumerator.Binary (enumHandle, iterHandle)
>      import Data.Enumerator.List as EL (map)
>      import Data.ByteString as B (map)
>      import Data.Bits (complement)
>      import System.IO (withFile, IOMode(..))
>      main = withFile "infile" ReadMode $ \inh -> withFile "outfile"
>      WriteMode $ \outh -> do
>          run_ (enumHandle 4096 inh $$ EL.map (B.map complement) =$ iterHandle outh)
> And many more - looks more like APL or Perl to me. :) Certainly not
> the Python'ish model of "anyone can read this, and it is clear what
> it does".

The promise of FP is certainly not that "anyone can read this and it
is clear what it does".  That's not really possible with any paradigm.
However, the above code to me does indeed seem wonderfully short and
clear: it opens an input and output files, then streams the contents
of the input file to the output file, while complemeting all the
bytes. You must at least agree that it is short.  And clarity depends
a lot on your background.  If you tried writing this program in most
mainstream languages I think you would find it to be longer and more

> Seems like the assertion that FP is easier and more clear is true at
> introductory levels, but there are some subsequent big gradients in
> the learning and usage curve. I use it only in very simple and small
> programs, so wondered about the observations on this from more
> experienced experts.

I think the perception of a big gradient in the learning and usage
curve is often due to the challenge of learning an entirely new
paradigm.  The learning and usage curve was quite steep for the first
programming language each of us learned, but we have mostly forgotten
about it by now.

> I wonder if any studies have been done to quantify and measure the
> complexity of programs in Haskell, as a way to assess this property.

Not that I am aware of.


More information about the Beginners mailing list