Oct. 23rd, 2008

juan_gandhi: (Default)
An example showing that you can't seriously do deeply-parameterized types without typedef:

public class NaturalTransformation<
    XObjects, // type of nodes in the first category (like Alksnis?)
    XArrows, // type of arrows in the first category
    YObjects, // type of nodes in the second category
    YArrows   // type of arrows in the second category
    >
    extends Morphism<
    Functor<XObjects, XArrows, YObjects, YArrows>,
    Functor<XObjects, XArrows, YObjects, YArrows>> {
  private SetMorphism<XObjects, Set<XObjects>, YArrows, Set<YArrows>> Fx_to_Gx;

  public NaturalTransformation(Functor<XObjects, XArrows, YObjects, YArrows> F,
                               Functor<XObjects, XArrows, YObjects, YArrows> G,
                               SetMorphism<XObjects, Set<XObjects>, YArrows, Set<YArrows>> Fx_to_Gx) {
    super(F, G);
    this.Fx_to_Gx = Fx_to_Gx;
  }

  public static <XObjects, XArrows, YObjects, YArrows>
  NaturalTransformation<
      XObjects,
      XArrows,
      YObjects,
      YArrows
      > unit(final Functor<XObjects, XArrows, YObjects, YArrows> F) {
    return new NaturalTransformation<
        XObjects,
        XArrows,
        YObjects,
        YArrows>(F, F,
        new SetMorphism<XObjects, Set<XObjects>, YArrows, Set<YArrows>>(
            F.domain().objects(), F.codomain().arrows()) {
          public YArrows apply(XObjects x) {
            return F.codomain().unit(F.nodesMorphism.apply(x));
          }
        }
    );
  }

  // TODO: implement it; currently it is just a copy of funit
  public static <XObjects, XArrows, YObjects, YArrows>
  NaturalTransformation<
      XObjects,
      XArrows,
      YObjects,
      YArrows
      > constant(final Functor<XObjects, XArrows, YObjects, YArrows> F) {
    return new NaturalTransformation<
        XObjects,
        XArrows,
        YObjects,
        YArrows>(F, F,
        new SetMorphism<XObjects, Set<XObjects>, YArrows, Set<YArrows>>(
            F.domain().objects(), F.codomain().arrows()) {
          public YArrows apply(XObjects x) {
            return F.codomain().unit(F.nodesMorphism.apply(x));
          }
        }
    );
  }

}

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

September 2025

S M T W T F S
 1 2345 6
78 9 10 111213
14 151617181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 16th, 2025 09:19 am
Powered by Dreamwidth Studios