Created
October 10, 2014 16:59
-
-
Save ChadSki/fe803bfeb5d34c731b28 to your computer and use it in GitHub Desktop.
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
def compose(f1, f2): | |
return lambda x: f1(f2(x)) |
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
/* declare a typedef for a function pointer */ | |
typedef double (*Class2Func)(double); | |
typedef struct sComposition { | |
Class2Func f1; | |
Class2Func f2; | |
} *Composition; | |
Composition Compose( Class2Func f1, Class2Func f2) | |
{ | |
Composition comp = malloc(sizeof(struct sComposition)); | |
comp->f1 = f1; | |
comp->f2 = f2; | |
return comp; | |
} | |
double CallComposed( Composition comp, double val ) | |
{ | |
return comp->f1( comp->f2(val) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment