Cardioid

Squares

Just random colorful stuff.

C11 ADTs (sort of)

Haskell:

data T = A | B Int | C Int Int | D T

hello :: T -> Int
hello t =
    case t of
        A       -> 0
        B x     -> x
        C x y   -> x + y
        D t'    -> hello t'

C11:

struct T {
    enum {
        T_TAGA, T_TAGB, T_TAGC, T_TAGD
    } tag;
    
    union {
        struct {
        } A;
        
        struct {
            int p0;
        } B;
        
        struct {
            int p0;
            int p1;
        } C;
        
        struct {
            struct T* p0;
        } D;
    };
};

int hello(const struct T* t) {
    switch (t->tag) {
    case T_TAGA:
        return 0;
    case T_TAGB:
        return t->B.p0;
    case T_TAGC:
        return t->C.p0 + t->C.p1;
    case T_TAGD:
        return hello(t->D.p0);
    default:
        fputs("missing pattern\n", stderr);
        abort();
    }
}