Last active
December 31, 2015 17:59
-
-
Save einarwh/8024076 to your computer and use it in GitHub Desktop.
Composing g and h functions from f-functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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