[Haskell-cafe] Is my code too complicated?
felipe.lessa at gmail.com
Sat Jul 3 08:42:10 EDT 2010
On Sat, Jul 3, 2010 at 9:25 AM, Ertugrul Soeylemez <es at ertes.de> wrote:
> 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.
When I first read this paragraph, I thought: "STM to the rescue!".
STM is one of the best concurrent world glues, IMHO.
> 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
Oh, so it is about monad transformers. =)
If you want, you may use Haskell just as you as PHP or C: just put
everything in IO. Your code will get uglier and the type system won't
catch many bugs, but that's what we get when doing C or PHP, right?
> 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.
I agree that it gets harder to reason about the code. In fact,
sometimes I stack monad transformers in the wrong order. However, as
Ivan says, if the feature is useful for you, don't be afraid of using
it. Beginners may have a hard time grasping the concepts for the
first time, but that's only until they "get it".
About monad transformers, I don't really like to use them because they
can get hairy in some cases, and because they have poor performance in
other cases. Yet the decision of using transformers or not should be
made depending on your particular needs.
> 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 ()
"It is the type of functions that may access and modify a state of type Config."
More information about the Haskell-Cafe