Skip to content

Instantly share code, notes, and snippets.

@okram
Last active October 30, 2020 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okram/cc3a786b9888abafef4a9551391e6b5f to your computer and use it in GitHub Desktop.
Save okram/cc3a786b9888abafef4a9551391e6b5f to your computer and use it in GitHub Desktop.
// all cascading coercion is completely determined within the obj graph and thus, realized as instructions.
mmlang> :[model,digraph]
==>_
mmlang> int
==>int
mmlang> int => nat
==>nat<=int[is,bool<=int[gt,0]]
mmlang> int => nat => vertex
==>vertex<=int[is,bool<=int[gt,0]][split,('id'->nat)]
mmlang> int => nat => vertex -<(_;_)
==>(vertex:('id'->nat,'attrs'->attr{*});vertex:('id'->nat,'attrs'->attr{*}))<=int[is,bool<=int[gt,0]][split,('id'->nat)][split,(vertex:('id'->nat,'attrs'->attr{*});vertex:('id'->nat,'attrs'->attr{*}))]
mmlang> int => nat => vertex -<(_;_) => edge
==>edge<=int[is,bool<=int[gt,0]][split,('id'->nat)][split,(vertex:('id'->nat,'attrs'->attr{*});vertex:('id'->nat,'attrs'->attr{*}))][split,('outV'->vertex<=(vertex:('id'->nat,'attrs'->attr{*});vertex:('id'->nat,'attrs'->attr{*}))[get,0,_],'inV'->vertex<=(vertex:('id'->nat,'attrs'->attr{*});vertex:('id'->nat,'attrs'->attr{*}))[get,1,_])]
// this demonstrates the 'cascading' aspect. you can go from int=>vertex cause the VM finds a path through nat
mmlang> int-<(vertex;vertex)
==>(vertex<=nat[split,('id'->nat)];vertex:('id'->nat,'attrs'->attr{*}))<=int[split,(vertex<=nat[split,('id'->nat)];vertex:('id'->nat,'attrs'->attr{*}))]
mmlang> int-<(vertex;vertex) => edge
==>edge<=int[split,(vertex<=nat[split,('id'->nat)];vertex:('id'->nat,'attrs'->attr{*}))][split,('outV'->vertex<=(vertex:('id'->nat);vertex:('id'->nat,'attrs'->attr{*}))[get,0,_],'inV'->vertex<=(vertex:('id'->nat);vertex:('id'->nat,'attrs'->attr{*}))[get,1,_])]
// finally, the integer 5 is coerced into an edge via int-<(vertex;vertex) and vertex-<(_;_).
// SRT is the coercion algebra. it provides the algebraic equalities of graph paths.
mmlang> 5 => int-<(vertex;vertex) => edge
==>edge:('outV'->vertex:('id'->nat:5),'inV'->vertex:('id'->nat:5))
mmlang> 5 => vertex
==>vertex:('id'->nat:5)
mmlang> 5 => vertex => -<(_;_) => edge
==>edge:('outV'->vertex:('id'->nat:5),'inV'->vertex:('id'->nat:5))
mmlang>
mmlang> 5 => vertex-<(_;_) => edge
==>edge:('outV'->vertex:('id'->nat:5),'inV'->vertex:('id'->nat:5))
mmlang>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment