[Haskell-cafe] modelling C in Haskell ..

Galchin, Vasili vigalchin at gmail.com
Fri May 30 03:29:17 EDT 2008


compactness in writing and also namespace pollution .. ;^)

Vasili


On Fri, May 30, 2008 at 2:12 AM, Jonathan Cast <jonathanccast at fastmail.fm>
wrote:

> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080530/df157348/attachment.htm


More information about the Haskell-Cafe mailing list