Name: Anonymous 2017-02-02 10:34
@davetchepak "What can C# do that F# cannot?"
NullReferenceException :-)
Educating the imperative gorillas about sum types:
https://chadaustin.me/2015/07/sum-types/
@davetchepak "What can C# do that F# cannot?"
NullReferenceException :-)
C, C++, Java, C#, Python etc still do not[have tagged unions].
enum ShapeKind { Square, Rectangle, Circle };
struct Shape {
int centerx;
int centery;
enum ShapeKind kind;
union {
struct { int side; }; /* Square */
struct { int length, height; }; /* Rectangle */
struct { int radius; }; /* Circle */
};
};
int getSquareSide(struct Shape* s) {
assert(s->kind == Square);
return s->side;
}
void setSquareSide(struct Shape* s, int side) {
s->kind = Square;
s->side = side;
}
/* and so on */