[Haskell-cafe] Is my code too complicated?

Ertugrul Soeylemez es at ertes.de
Sat Jul 3 08:25:22 EDT 2010

Hello fellow Haskellers,

I'd like to discuss an interesting topic.  My experience is that there
are two worlds in Haskell, which are quite separate:  the pure,
algorithmic world, where you use idiomatic pure Haskell, and the
IO-driven world of state, change, threads and execution, where you use
idiomatic concurrent Haskell.

If you understand these two concepts well, then you are usually a good
Haskell programmer.  Interestingly this doesn't mean that you get
applications done faster or done at all.  Most languages today provide a
certain "glue" to bring everything together.  I think that term
originates from "Why Functional Programming Matters" by John Hughes.

Haskell provides a lot of low level glue like laziness, currying and
other very helpful language features.  But what is different in Haskell
is that it doesn't seem to provide any high level glue like other
languages do, especially when it comes to the IO world.  There is a
somewhat powerful module system, but nothing to bring modules and the
objects they define together in a consistent way.

In my opinion this is both a disadvantage and an advantage.  It's bad
because there is no standard way of gluing, nothing everybody learns and
uses.  On the other hand it's good, because you can make your own glue.
This has proven very useful for me.  My usual way is writing monad
transformers and sticking them together, often together with concurrent

The problem with that approach is:  This makes my code harder to
understand for beginners.  Usually they can tell /what/ my code is
doing, because it's written in natural language as much as possible, but
they couldn't reproduce it.  And when they try to learn it, they give up
fast, because you need quite some background for that.  Also sometimes
when I write Haskell, my friend sits beside me and watches.  When he
asks (as a PHP programmer with some C background), say, about my types,
I can't give a brief explanation like I could in other languages.

Yesterday I was writing a toy texture handler for OpenGL (for loading
and selecting textures).  He asked about my TextureT type.  I couldn't
explain it, because you couldn't even express such a thing in PHP or C.

  type TextureT = StateT Config

  -- Note that this is MonadLib.
  -- BaseM m IO corresponds to MonadIO m.
  selectTexture :: BaseM m IO => B.ByteString -> TextureT m ()

I fear that my code is already too difficult to understand for
beginners, and it's getting worse.  But then I ask myself:  I've got a
powerful language, so why shouldn't I use that power?  After all I
haven't learnt Haskell to write C code with it.  And a new Haskell
programmer doesn't read my code to learn Haskell.  They first learn
Haskell and /then/ read my code.

Is this a real problem or am I just exaggerating?
What do you think?


nightmare = unsafePerformIO (getWrongWife >>= sex)

More information about the Haskell-Cafe mailing list