[Haskell-cafe] Re: Datatypes - Haskell

Jason Dusek jsnx at lolcatbible.com
Sun Feb 10 23:17:33 EST 2008

Mattes Simeon <simeon.mattes at gmail.com> wrote:
> Though in comparison with C or C++ I can't figure out so clear
> the syntax...I seems realy strange, and I'm confused.
> Surely a solution to this would be to use the standard types
> of Haskel for tuples and check out each time if I have just a
> number or a tuple. But this is how somebody thinks in
> imperative languages. Functional programming is something
> more...

The data declarations in Haskell are well-suited to pattern
matching -- you have a compact way to express each alternative,
so you can match on that alternative. The C++ way offers a
*uniform* interface to every alternative, so you can do if-tests
that will type check. The "do an if test at runtime" way is very
general, but basically unoptimizable; whereas pattern matching
is very specific, and can be optimized (see page 5 of Luca
Cardelli's [Compiling ML]).

> Sorry for beeing so naive, but although unions, enum,
> structure are just some tools in C, surely something more in
> C++, in Haskell they are seem to be a standard.

It's certainly true that Haskell elevates certain common data
structures to the level of 'native citizens', providing short
cut syntax and so forth. Personally, I think C's approach is an
example of neglect in this domain, not sparseness; however, at
the time C was introduced, I would not have said the same thing
at all.


[Compiling ML]:     http://lucacardelli.name/Papers/CompilingML.pdf

More information about the Haskell-Cafe mailing list