You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current query engine is almost 1:1 API wrapper for erlang matchspecs. It would be neat to make the API both more functional and type safe, there are a couple of routes.
Typed Algebra
Instead of having a loose algebra for matchspecs implement a recursive Algebra that would always guarantee these are built correctly.
pubtypeTerm(x){Var(x)IgnoreValue(x)}pubopaquetypeConstructor(a, b, c, d, e, f, g, h, i, record){Constructor0(fn()-> record)Constructor1(fn(a)-> record)Constructor2(fn(a, b)-> record)Constructor3(fn(a, b, c)-> record)Constructor4(fn(a, b, c, d)-> record)Constructor5(fn(a, b, c, d, e)-> record)Constructor6(fn(a, b, c, d, e, f)-> record)Constructor7(fn(a, b, c, d, e, f, g)-> record)}pubopaquetypeSpec(a, b, c, d, e, f, g, h, i){Spec0(#())Spec1(#(Term(a)))Spec2(#(Term(a),Term(b)))Spec3(#(Term(a),Term(b),Term(c)))Spec4(#(Term(a),Term(b),Term(c),Term(d)))Spec5(#(Term(a),Term(b),Term(c),Term(d),Term(e)))Spec6(#(Term(a),Term(b),Term(c),Term(d),Term(e),Term(f)))Spec7(#(Term(a),Term(b),Term(c),Term(d),Term(e),Term(f),Term(g)))}
Functional API
One way to make the API a bit more functional would be to have a bind function that works on constructors and other functions.
fnbind(query,constructor)->Query(index, record, x){let#(#(index,record),conditions,body)=queryletshape=ffi_build_matchhead(constructor)#(#(index,shape),conditions,shape)}@external(erlang,"lamb_erlang_ffi","from_constructor")fnffi_from_constructor(constructor: constructor)-> record
A big disadvantage of this approach is that it can introduce unexpected crashes, most non-opaque constructors would work very well but custom functions will try to do invalid operations like:
The current query engine is almost 1:1 API wrapper for erlang matchspecs. It would be neat to make the API both more functional and type safe, there are a couple of routes.
Typed Algebra
Instead of having a loose algebra for matchspecs implement a recursive Algebra that would always guarantee these are built correctly.
Functional API
One way to make the API a bit more functional would be to have a bind function that works on constructors and other functions.
Then on erlang's FFI:
A big disadvantage of this approach is that it can introduce unexpected crashes, most non-opaque constructors would work very well but custom functions will try to do invalid operations like:
This approach was implemented in v0.4.1 with good but magical results.
Typed bindings
Have intermediate types that hold the table together, possible APIs:
Check the decode and zero APIs and learn more about continuations for functional programming:
The text was updated successfully, but these errors were encountered: