Permalink
Browse files

Allow 0-arg composing of a parametrized role without first currying it

  • Loading branch information...
1 parent 4a19356 commit 32a629ca6567e9f4fe3d5886e007e47fe28b302a @sorear sorear committed Jan 4, 2012
Showing with 13 additions and 7 deletions.
  1. +13 −7 lib/Kernel.cs
View
@@ -5361,12 +5361,15 @@ internal class MMDCandidate : MultiCandidate {
}
public static Frame InstantiateRole(Frame th, Variable[] pcl) {
- STable prole = pcl[0].Fetch().mo;
+ th.resultSlot = DoInstantiateRole(pcl[0].Fetch().mo,pcl[1]).typeVar;
+ return th;
+ }
+ public static STable DoInstantiateRole(STable prole, Variable alist) {
// get argument list - TODO make this saner
- P6any argv = pcl[1].Fetch();
+ P6any argv = alist.Fetch();
Variable[] args = argv.mo == Kernel.ParcelMO ?
- UnboxAny<Variable[]>(argv) : new Variable[] { pcl[1] };
+ UnboxAny<Variable[]>(argv) : new Variable[] { alist };
STable r = new STable(prole.name + "[curried]");
r.mo.roleFactory = prole.mo.roleFactory;
@@ -5381,8 +5384,7 @@ internal class MMDCandidate : MultiCandidate {
foreach (var ai in prole.mo.local_attr)
r.mo.local_attr.Add(ai);
r.mo.Invalidate();
- th.resultSlot = r.typeVar;
- return th;
+ return r;
}
static STable ToComposable(STable arg) {
@@ -5416,9 +5418,13 @@ internal class MMDCandidate : MultiCandidate {
}
r.mo.Invalidate();
return r;
+ } else if (arg.mo.type == P6how.PARAMETRIZED_ROLE) {
+ return ToComposable(DoInstantiateRole(arg, Builtins.MakeParcel()));
+ } else if (arg.mo.type == P6how.ROLE) {
+ return arg;
+ } else {
+ throw new NieczaException("Cannot compose a type of category " + arg.mo.rtype);
}
-
- return arg;
}
public static STable RoleApply(STable b, STable role) {

0 comments on commit 32a629c

Please sign in to comment.