01: package JSci.maths.categories;
02:
03: /**
04: * The HomFunctor class encapsulates the hom-bifunctor.
05: * @version 1.0
06: * @author Mark Hale
07: */
08: public class HomFunctor extends Object implements Bifunctor {
09: private Category cat;
10:
11: /**
12: * Constructs the hom bifunctor for a category.
13: */
14: public HomFunctor(Category c) {
15: cat = c;
16: }
17:
18: /**
19: * Maps two objects to another.
20: */
21: public Object map(Object a, Object b) {
22: return cat.hom(a, b);
23: }
24:
25: /**
26: * Maps two morphisms to another.
27: */
28: public Category.Morphism map(Category.Morphism m,
29: Category.Morphism n) {
30: return new HomMorphism(m, n);
31: }
32:
33: private class HomMorphism implements Category.Morphism {
34: private Category.Morphism in, out;
35:
36: public HomMorphism(Category.Morphism m, Category.Morphism n) {
37: in = m;
38: out = n;
39: }
40:
41: public Object domain() {
42: return cat.hom(in.codomain(), out.domain());
43: }
44:
45: public Object codomain() {
46: return cat.hom(in.domain(), out.codomain());
47: }
48:
49: public Object map(Object o) {
50: return in.compose((Category.Morphism) o).compose(out);
51: }
52:
53: public Category.Morphism compose(Category.Morphism m) {
54: HomMorphism hm = (HomMorphism) m;
55: return new HomMorphism(hm.in.compose(in), out
56: .compose(hm.out));
57: }
58: }
59: }
|