01: /**************************************************************************/
02: /* N I C E */
03: /* A simple imperative object-oriented research language */
04: /* (c) Daniel Bonniot 1999 */
05: /* */
06: /* This program is free software; you can redistribute it and/or modify */
07: /* it under the terms of the GNU General Public License as published by */
08: /* the Free Software Foundation; either version 2 of the License, or */
09: /* (at your option) any later version. */
10: /* */
11: /**************************************************************************/package mlsub.typing;
12:
13: import mlsub.typing.lowlevel.*;
14:
15: /**
16: * The kind of tuples (one per arity).
17: *
18: * @author Daniel Bonniot
19: */
20:
21: public class TupleKind implements Kind {
22: public static TupleKind get(int arity) {
23: if (tupleKinds[arity] == null)
24: tupleKinds[arity] = new TupleKind(arity);
25: return tupleKinds[arity];
26: }
27:
28: private TupleKind(int arity) {
29: this .arity = arity;
30:
31: // forces the creation of the constraint
32: // we don't want it to be created during link.
33: Engine.getConstraint(this );
34: }
35:
36: /** Arity arbitrarily limited to 200 for implementation reasons. */
37: private static final TupleKind tupleKinds[] = new TupleKind[200];
38:
39: public Monotype freshMonotype(boolean existential) {
40: Monotype[] args = MonotypeVar.news(arity, existential);
41: Typing.introduce(args);
42:
43: return new TupleType(args);
44: }
45:
46: public void register(Element e) {
47: }
48:
49: public void leq(Element e1, Element e2, boolean initial)
50: throws Unsatisfiable {
51: if (initial)
52: throw new InternalError("initial leq in TupleKind");
53: leq(e1, e2);
54: }
55:
56: public void leq(Element e1, Element e2) throws Unsatisfiable {
57: TupleType t1 = tuple(e1), t2 = tuple(e2);
58:
59: Engine.leq(t1.types, t2.types);
60: }
61:
62: private TupleType tuple(Element e) {
63: try {
64: return (TupleType) ((Monotype) e).equivalent();
65: } catch (ClassCastException ex) {
66: throw new InternalError(e
67: + " was expected to be a tuple type, it's a "
68: + e.getClass());
69: }
70: }
71:
72: public String toString() {
73: return "Tuple(" + arity + ")";
74: }
75:
76: int arity;
77: }
|