Skip to content

Instantly share code, notes, and snippets.

@iconmaster5326
Last active October 19, 2018 23:30
Show Gist options
  • Select an option

  • Save iconmaster5326/1892d71a421544ba71fd64e75c709633 to your computer and use it in GitHub Desktop.

Select an option

Save iconmaster5326/1892d71a421544ba71fd64e75c709633 to your computer and use it in GitHub Desktop.
Catacomb Composition Algorithm

Composition is the act of taking a stack and a function, and producing the type signature of the resulting stack. It can also be equivalenty seen as the composition of two functions' execution.

  1. Generate constraints from the stated type sigs of your functions.
  2. Match the RHS of the LHF, and the LHS of the RHF, from right to left. If the two symbols are:
    • Base types: Fail if one is not a parent type of the other. Otherwise, do nothing.
    • Both function types: Recursively generate constraints, starting with {a} = {b} and expanding the functions using the rule {--} ==> {a -- a} until one constraint set successfully unifies.
    • One is a variardic type: Recursively generate constraints, starting with a = and epanding the constraint to capture more values on the other side until one constraint set successfully unifies.
    • Else: generate a constraint a = b and move on.
  3. Return the result of the first unification that succeeds. If you unify a -- b1 b2 and c1 c2 -- d, where b1/c1 are unmatched portions and b2/c2 are matched ones, you get a c1 -- b1 d.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment