[Haskell-cafe] what I learnt from my first serious haskell programm
fmohamed at mac.com
Sat Mar 17 07:04:06 EDT 2007
I came to haskell recently (one month) and I have now written my first
I am still busy improving it, but here is a small report of what I
learned and and my impressions of the language.
I found no show stoppers, but a couple of things that I didn't like much.
* namespaces *
First off something that disturbed me but does not seem to be discussed
much are namespaces, or rather the lack of them.
Yes I know that haskell does have namespaces, but with object oriented
languages you basically get a namespace for each class, in haskell you
need modules, and I often like to have groups of related types in the
This might seem like a small issue, but the fact when a program or
library grows it gets worse, and for me having a consistent way of
calling functions is very important, it lets me spend less time thinking
about naming. This is something makes the difference between a set of
libraries and well thought out framework.
Records then also put everything in the module namespace, and it seems
that this misfeature has already been discussed.
Anyway the namespaces would not be a problem if one would use always the
most specialized function (and throw an error is no such function exist)
as for example is done by Aldor ( http://www.aldor.org ) a language with
a very nice type system, that unfortunately has been kind of dying for a
long time because of its closed source.
So I am wondering how people cope with them, share your opinion,
for me the best thing seem to be to try to use one
module per "big" type, and then "import qualified x as y", what are
good coding practices?
* space leaks *
Sure enough in my program I had a space leak, actually an exponential
The short story: it did bite me, and I think that many people that have
problems with the performance in haskell, is because of them.
The whole story is that I wanted to find the optimal node at depth n of an infinite tree.
I even wrote down the list of the optimal nodes at each depth from which
I would take some, but even before compiling it I realized that this
would never be efficient.
So I passed the maximum depth as argument to the function that generates
and immediately reduces the tree.
It had a huge space leak, and I knew what was happening, the function
wad doing a breath first search of the tree instead of a depth first
search, so I put a seq to make it go deeper first.
It helped, but a space leak was still there.
So I used the profiler, and basically the default profiler is useless
for space leaks (it just says the total amount allocated which was constant).
After some thinking I finally found out (a posteriori obvious) that I
had to fully evaluate the actual node the the depth, and finally return
In the meantime I had introduced a couple of seq too much, and also
switched to a strict data structure (which helped a little but was not
the biggest issue.
I really looked into memory profiling after having fixed the problem
(but having seen how much work it could be even when you know where the
I tried to use it and I think that it would have been useful, I will see
how much with the next bug.
With respect to this bibliographical heap profile (+RTS -hb) is broken
on my AMD 64 Linux machine with GHC 6.6.20070129, I submitted a bug.
* vector & matrices *
A thing that bothered me a little was the absence of good standardized
vectors and matrices, for now I rolled my own 3x3, I have seen numerical
prelude, maybe in the future thre will be a standard interface for matrixes...
Rolling my own mattrixes/vectors I have hit against some limitations of
classes, nothing terrible, but not so nice, and something that I gather is
known for example the fact that you cannot overload + or (in haskell 98)
you cannot have overlapping instances.
Again (see namespaces problem) changing names for the operations
is the way out but it is not so nice.
* parallel *
For the future I want to make my algorithm parallel using threads (should be
Then I was thinking about being parallel between computers, so to have
really make this exercice a test if I really can switch to haskell for
my programming, I was thinking about MPI, suggestions?
thanks for having read till here :)
More information about the Haskell-Cafe