Ejemplo n.º 1
0
  @Override
  public Functor visit(FQLProgram env, FinalConst ic) {
    CatExp e = resolve(env, ic.src);
    if (!(e instanceof Const)) {
      throw new RuntimeException("Can only create functors from finitely-presented categories.");
    }
    Const c = (Const) e;

    Category cat = c.accept(env, this);
    Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);

    Category target = ic.C.accept(env, this);

    Map<Node, Functor> nm = new HashMap<>();
    for (Node n : sig.nodes) {
      FunctorExp kkk = ic.nm.get(n.name);
      if (kkk == null) {
        throw new RuntimeException("Missing node mapping from " + n);
      }
      Functor F = kkk.accept(env, this);
      nm.put(n, F);
    }
    Map<Edge, Transform> em = new HashMap<>();
    for (Edge n : sig.edges) {
      TransExp chc = ic.em.get(n.name);
      if (chc == null) {
        throw new RuntimeException("Missing edge mapping from " + n);
      }
      em.put(n, chc.accept(env, this));
    }

    FUNCTION fff =
        p0 -> {
          Path p = (Path) p0;
          Object fn = target.identity(nm.get(p.source));
          for (Object nnn : p.path) {
            Edge n = (Edge) nnn;
            fn = target.compose(fn, em.get(n));
          }
          return fn;
        };

    return new Functor<>(cat, target, x -> nm.get(x), fff);
  }