Skip to content

Instantly share code, notes, and snippets.

@einarwh
Last active December 31, 2015 17: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 einarwh/8024076 to your computer and use it in GitHub Desktop.
Save einarwh/8024076 to your computer and use it in GitHub Desktop.
Composing g and h functions from f-functions.
private Func<EvalStack, EvalStack> CreateG()
{
return CreateComposite(_first, _last);
}
private Func<EvalStack, EvalStack> CreateComposite(
Instruction first,
Instruction last)
{
Instruction insn = first;
Func<EvalStack, EvalStack> fun = stack => stack;
while (insn != null)
{
var f = CreateF(insn);
var fresh = fun;
fun = stack => f(fresh(stack));
insn = (insn == last) ? null : insn.Next;
}
return fun;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment