sigsolve

type signature satisfiability solver under function composition

Usage no npm install needed!

<script type="module">
  import sigsolve from 'https://cdn.skypack.dev/sigsolve';
</script>

README

sigsolve

find a path through a type signature pool

testling badge

build status

example

var sigsolve = require('sigsolve');
var pool = {
    f : [ 'a', 'b' ],
    g : [ 'b', 'x' ],
    h : [ 'x', 'z' ],
    i : [ 'c', 'z' ],
    j : [ 'c', 'd' ],
};

var solutions = sigsolve([ 'a', 'z' ], pool);
console.dir(solutions);

output:

[ [ 'f', 'g', 'h' ] ]

or higher-order signatures work too:

var sigsolve = require('sigsolve');
var pool = {
    f : [ [ 'a', 'b' ], 'c' ],
    g : [ 'c', 'z' ],
    h : [ 'a', 'd' ],
    i : [ 'd', 'b' ],
};
var solutions = sigsolve([ 'a', 'z' ], pool);
console.log(JSON.stringify(solutions));

output:

[[["f",["h","i"]],"g"]]

methods

var sigsolve = require('sigsolve')

var solutions = sigsolve(target, pool)

Given a type signature target and an object pool mapping function names to type signatures,

return an array of function chain arrays that when composed have the same type signature as the target.

license

MIT