On Typed Metadata

On Typed Metadata

While it's sort of germane to the typed metadata discussion, it seems rude to jump on the thread with a pretty different idea of it so here are my notes.

One of the problems for macro usage is that Expr and Type are bound, so if you want to handle types you also have to handle expressions.

They are bound in `MetadataEntry'

typedef MetadataEntry = {
    var name:String;
    var ?params:Array<Expr>;
    var pos:Position;
}

Also Expr is found in ComplexType so that to handle type annotations you have to start with expressions.

This can be fixed with a small AST for literals like Clojure's EDN, something like:

enum EDN{
    PLabel(name:String);// :object_key
    PApply(name:String);// #do_something_with_this
    PGroup(list:LinkedList<PExpr<T>>);//(parens)
    PArray(array:Cluster<PExpr<T>>);//[array]
    PValue(value:Atom);//primitive
    PEmpty;//ZERO
    PAssoc(map:Cluster<Tup2<PExpr<T>,PExpr<T>>>);//Map
    PSet(arr:Cluster<PExpr<T>>);//Set
}
enum Atom{//Data, Eq, Show, Typeable)
  AnSym(s:Symbol);
  B(b:Bool);
  N(fl:Num);
  Str(str:String);
  Nul;
}

Then Type and Expr are separate and you can build a little type description for literals by itself and use some simple mechanism to match these up

An array of a map of string and atom

(TPArray (TPAssoc TPLabel TPAtom)))
([{:some_key 1 :keying true} {:other 2}])

If you were to survey of what Metadata there is in the wild, you'd probably find that there is vanishing little of it is more complicated than Array<String>

EDN is perfect because it is a superset of most data formats, it can handle XML and JSON structures and anything else.

You could, for example, constrain it to a JSON like shape for runtime and allow a larger subset in macros.

It's probably a macro.