[Haskell-beginners] Haskell-style types in C or C++

John Harrison ash.gti at gmail.com
Sun Jul 31 00:13:32 CEST 2011


For:

Data QueryResult = NoResult | DatabaseError String | Results [String]

A close approximation I can think of is:

enum {NoResult, DatabaseError, Results};
struct QueryResult {
    int type;
    union {
        char* error_msg;
        struct {
            char** msgs;
            int len;
        } results;
    };
};

https://gist.github.com/1116058 is a simple use case of the code I
suggested. I am not sure there is only 1 solution to this though.

On Sat, Jul 30, 2011 at 1:45 PM, Christopher Howard <
christopher.howard at frigidcode.com> wrote:

> One of the things that I love about Haskell is the syntax for creating user
> defined types. E.g.:
>
> Data QueryResult = NoResult | DatabaseError String | Results [String]
>
> I can prototype an entire program around these self-made types and it is a
> lot of fun. Out of intellect curiosity, though: what would be the equivalent
> construction in C or C++? (Say, for the type defined above).
>
> --
> frigidcode.com
> theologia.indicium.us
>
> ______________________________**_________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>



-- 
John Harrison
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110730/d8eff885/attachment.htm>


More information about the Beginners mailing list