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

Thomas Davie tom.davie at gmail.com
Sun Jul 31 00:10:19 CEST 2011


typedef enum
{
    QueryResultTypeNoResult,
    QueryResultTypeDatabaseError,
    QueryResultTypeResults
} QueryResultType;

typedef union
{
    char *error;
    char **results;
} QueryResultData;

typedef struct
{
    QueryResultType type;
    QueryResultData data;
} QueryResult

Or something to that effect…

Bob

On 30 Jul 2011, at 19:45, Christopher Howard 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




More information about the Beginners mailing list