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.Kind;
14:
15: /**
16: A tuple type.
17:
18: @author Daniel Bonniot
19: */
20:
21: public class TupleType extends Monotype {
22: public TupleType(Monotype[] types) {
23: this .types = types;
24:
25: kind = TupleKind.get(types == null ? 0 : types.length);
26: }
27:
28: public Monotype[] getComponents() {
29: return types;
30: }
31:
32: public boolean isRigid() {
33: return Monotype.isRigid(types);
34: }
35:
36: Monotype substitute(java.util.Map map) {
37: return new TupleType(Monotype.substitute(map, types));
38: }
39:
40: /****************************************************************
41: * low-level interface
42: ****************************************************************/
43:
44: public int getId() {
45: return mlsub.typing.lowlevel.Engine.INVALID;
46: }
47:
48: public void setId(int value) {
49: throw new Error();
50: }
51:
52: final Kind kind;
53:
54: public Kind getKind() {
55: return kind;
56: }
57:
58: public void setKind(Kind value) {
59: throw new Error();
60: }
61:
62: /****************************************************************
63: * Misc.
64: ****************************************************************/
65:
66: public boolean equals(Object o) {
67: if (!(o instanceof TupleType))
68: return false;
69:
70: return types.equals(((TupleType) o).types);
71: }
72:
73: public String toString() {
74: return bossa.util.Util.map("(", ", ", ")", types);
75: }
76:
77: Monotype[] types;
78:
79: /****************************************************************
80: * Simplification
81: ****************************************************************/
82:
83: void tag(int variance) {
84: Monotype.tag(types, variance);
85: }
86:
87: Monotype canonify() {
88: types = Monotype.canonify(types);
89: return this;
90: }
91: }
|