use of catdata.fqlpp.cat.Functor in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, FunctorExp.Exp e) {
Functor l = e.l.accept(env, this);
Functor r = e.r.accept(env, this);
if (FinSet.FinSet.equals(l.target) && FinSet.FinSet.equals(r.target)) {
if (!l.source.equals(r.source)) {
throw new RuntimeException("Source categories do not match");
}
return Inst.get(l.source).exp(l, r);
}
if (FinCat.FinCat.equals(l.target) && FinCat.FinCat.equals(r.target)) {
if (!l.source.equals(r.source)) {
throw new RuntimeException("Source categories do not match");
}
throw new RuntimeException("Not implemented yet");
// return FunCat.get(l.source).product(l, r);
}
throw new RuntimeException("Cannot exponentiate " + l + " and " + r);
}
use of catdata.fqlpp.cat.Functor in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, Apply e) {
Functor ret1 = null;
Exception ret1_e = null;
Functor ret2 = null;
Exception ret2_e = null;
Functor F = e.F.accept(env, this);
try {
Functor I = e.I.accept(env, this);
ret1 = (Functor) F.applyO(I);
} catch (Exception ex) {
ret1_e = ex;
}
try {
Var I = (Var) e.I;
Node n = F.source.toSig().new Node(I.v);
ret2 = (Functor) F.applyO(n);
} catch (Exception ex) {
ret2_e = ex;
}
if (ret1 != null && ret2 != null) {
throw new RuntimeException("Ambiguous: " + e.I + " is an object in two different categories.");
}
if (ret1 != null) {
return ret1;
}
if (ret2 != null) {
return ret2;
}
if (ret1_e != null) {
// TODO !!!
ret1_e.printStackTrace();
}
if (ret2_e != null) {
ret2_e.printStackTrace();
}
throw new RuntimeException("Cannot apply:\n\nmost probable cause: " + ret1_e + "\n\nless probable cause: " + ret2_e);
}
use of catdata.fqlpp.cat.Functor in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, SetSet e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
FUNCTION o = x -> {
Set set = (Set) x;
FQLPPEnvironment env2 = new FQLPPEnvironment(ENV);
// SetExp c = new SetExp.Const(set);
env2.sets.put(e.ob, set);
return e.fun.accept(env, new SetOps(env2));
};
return new Transform(s, t, o);
}
use of catdata.fqlpp.cat.Functor in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToInst e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
FUNCTION o = x -> {
Node n = (Node) x;
// Set src = (Set) s.applyO(n);
// Set dst = (Set) t.applyO(n);
Transform fun = e.fun.get(n.name).accept(env, this);
// new Fn(src, dst, fun);
return fun;
};
return new Transform(s, t, o);
}
use of catdata.fqlpp.cat.Functor in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToCat e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
FUNCTION o = x -> {
Node n = (Node) x;
// Set src = (Set) s.applyO(n);
// Set dst = (Set) t.applyO(n);
Functor fun = e.fun.get(n.name).accept(env, this);
// new Fn(src, dst, fun);
return fun;
};
return new Transform(s, t, o);
}
Aggregations