[Haskell-cafe] Re: modelling C in Haskell ..

Ben Franksen ben.franksen at online.de
Mon Jun 2 14:53:30 EDT 2008

Galchin, Vasili wrote:
> typedef struct blah
> {
>        int val1;
>        union {
>            int  val2;
>            struct {
>                  int val3;
>                  int val4;
>            }
>        }
> }    C_type;
> question: in Haskell, can I embed definition of the "union" inside of the
> C typedef, i.e. recursion definition? Or must I have a separate definition
> for the "union" which I "instantiate" inside the Haskell "typedef", i.e.
> Haskell "data"?

No. Each definition of a data type must occur at the top-level. Also,
Haskell has only a very weak record system, a deficit that is generally
agreed to be one of Haskell's greatest weaknesses.

Like jcc, I'd also be interested what concrete problem prompted your
question. While I have often found it annoying that in Haskell e.g. record
labels are global in scope, I have never encountered a situation where I
wanted to have lexically nested data type declarations.


More information about the Haskell-Cafe mailing list