Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
36
Task/Y-combinator/Chapel/y-combinator-1.chapel
Normal file
36
Task/Y-combinator/Chapel/y-combinator-1.chapel
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
proc fixz(f) {
|
||||
record InnerFunc {
|
||||
const xi;
|
||||
proc this(a) { return xi(xi)(a); }
|
||||
}
|
||||
record XFunc {
|
||||
const fi;
|
||||
proc this(x) { return fi(new InnerFunc(x)); }
|
||||
}
|
||||
const g = new XFunc(f);
|
||||
return g(g);
|
||||
}
|
||||
|
||||
record Facz {
|
||||
record FacFunc {
|
||||
const fi;
|
||||
proc this(n: int): int {
|
||||
return if n <= 1 then 1 else n * fi(n - 1); }
|
||||
}
|
||||
proc this(f) { return new FacFunc(f); }
|
||||
}
|
||||
|
||||
record Fibz {
|
||||
record FibFunc {
|
||||
const fi;
|
||||
proc this(n: int): int {
|
||||
return if n <= 1 then n else fi(n - 2) + fi(n - 1); }
|
||||
}
|
||||
proc this(f) { return new FibFunc(f); }
|
||||
}
|
||||
|
||||
const facz = fixz(new Facz());
|
||||
const fibz = fixz(new Fibz());
|
||||
|
||||
writeln(facz(10));
|
||||
writeln(fibz(10));
|
||||
48
Task/Y-combinator/Chapel/y-combinator-2.chapel
Normal file
48
Task/Y-combinator/Chapel/y-combinator-2.chapel
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// this is the longer version...
|
||||
/*
|
||||
proc fixy(f) {
|
||||
record InnerFunc {
|
||||
const xi;
|
||||
proc this() { return xi(xi); }
|
||||
}
|
||||
record XFunc {
|
||||
const fi;
|
||||
proc this(x) { return fi(new InnerFunc(x)); }
|
||||
}
|
||||
const g = new XFunc(f);
|
||||
return g(g);
|
||||
}
|
||||
// */
|
||||
|
||||
// short version using direct recursion as Chapel has...
|
||||
// note that this version of fix uses function recursion in its own definition;
|
||||
// thus its use just means that the recursion has been "pulled" into the "fix" function,
|
||||
// instead of the function that uses it...
|
||||
proc fixy(f) {
|
||||
record InnerFunc { const fi; proc this() { return fixy(fi); } }
|
||||
return f(new InnerFunc(f));
|
||||
}
|
||||
|
||||
record Facy {
|
||||
record FacFunc {
|
||||
const fi;
|
||||
proc this(n: int): int {
|
||||
return if n <= 1 then 1 else n * fi()(n - 1); }
|
||||
}
|
||||
proc this(f) { return new FacFunc(f); }
|
||||
}
|
||||
|
||||
record Fiby {
|
||||
record FibFunc {
|
||||
const fi;
|
||||
proc this(n: int): int {
|
||||
return if n <= 1 then n else fi()(n - 2) + fi()(n - 1); }
|
||||
}
|
||||
proc this(f) { return new FibFunc(f); }
|
||||
}
|
||||
|
||||
const facy = fixy(new Facy());
|
||||
const fibz = fixy(new Fiby());
|
||||
|
||||
writeln(facy(10));
|
||||
writeln(fibz(10));
|
||||
Loading…
Add table
Add a link
Reference in a new issue