[Haskell-cafe] modelling C in Haskell ..
Jonathan Cast
jonathanccast at fastmail.fm
Fri May 30 03:12:19 EDT 2008
On 29 May 2008, at 11:46 PM, Galchin, Vasili wrote:
> Hello,
>
> I don't want to write kludgy Haskell code!
>
> 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"?
Assuming all of these are semantic, you can say
newtype HS_type = HS_type (Int, Either Int (Int, Int))
But you lose named fields.
It's hard to give other advice without some idea of /why/ you want to
do something like this.
jcc
More information about the Haskell-Cafe
mailing list