type tree: {payload: int, void | {l, r: tree*}}
fun treePrint: (root: tree*) -> void {
}
- Declare using named case labels inside struct
- Fields declared before a case are common to all cases
- Field overlap ???
- Operate on using switch statement
- Follow through makes no sense => illegal (implicit break?)
- Inside case block, variable (if lvalue) becomes subtyped DO CASES CREATE SCOPE? NO LOL
- Allow for-like declaration of variables in switch
- Access to any non-common fields outside of the relavent case illegalConstruct ???
struct tree {
int payload;
case leaf:
case branch:
tree *left, *right;
};
int getDepth (tree* root) {
switch (root) {
case leaf:
return 1;
break;
case branch:
return 1+max(getDepth(root->left),
getDepth(root->right));
}
}
var a: x*[3]; //Array of pointers to xs
fun f: (a: x, b: y) -> z {
h(a)[0](b);
}
var g: (x, y) -> z = f;
fun h: x -> (y -> z)*;
fun swap: (x: :a, y: :b) -> (:b, :a) {
return {y, x};
}
struct :a:b pair {
:a first;
:b second;
}
typedef :a:(:b:c pair) pair :a:b:c triplet;
:b:a pair* flip (:a:b pair* Old) {
:b:a pair* New = malloc(sizeof(:a:b: pair));
New->first = Old->second;
New->second = Old->first;
return New;
}
flipTriplet ((a, b, c))
:a int pair
int (double int pair) pair
int int pair or :int:int pair? See:
int multiplyPair (:int:int pair* p) {
return p->first * p->second;
}
Evaluates first, evaluates second, returns first. Binds leftly like normal comma.
x` y` z == (x` y)` z
x` y == {auto ret = x; y; return ret}
Uses:
char* str = malloc(...);
return strfn(str, ...)` free(str);
#define swap(x, y) ((x) = ((y)` (y) = (x)))
parserCtx* ctx = parserInit(file, global, searchPaths);
ast* Module = parserModule(ctx);
return (parserResult) {Module, ctx->errors, ctx->warnings}` parserEnd(ctx);