01: /**************************************************************************/
02: /* B O S S A */
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 Arrow kind.
17: *
18: * @author bonniot
19: */
20:
21: public class FunTypeKind implements Kind {
22: public static FunTypeKind get(int domainArity) {
23: if (funtypeKinds[domainArity] == null)
24: funtypeKinds[domainArity] = new FunTypeKind(domainArity);
25: return funtypeKinds[domainArity];
26: }
27:
28: private static FunTypeKind[] funtypeKinds;
29:
30: public static void reset() {
31: funtypeKinds = new FunTypeKind[400];
32: }
33:
34: private FunTypeKind(int domainArity) {
35: this .domainArity = domainArity;
36: // forces the creation of the constraint
37: // we don't want it to be created during link.
38: Engine.getConstraint(this );
39: }
40:
41: public Monotype freshMonotype(boolean existential) {
42: Monotype codomain = new MonotypeVar(existential);
43: Typing.introduce(codomain);
44:
45: Monotype[] domain = MonotypeVar.news(domainArity, existential);
46: Typing.introduce(domain);
47:
48: return new FunType(this , domain, codomain);
49: }
50:
51: public void register(Element e) {
52: }
53:
54: public void leq(Element e1, Element e2, boolean initial)
55: throws Unsatisfiable {
56: if (initial)
57: throw new InternalError("initial leq in FunTypeKind");
58: leq(e1, e2);
59: }
60:
61: public void leq(Element e1, Element e2) throws Unsatisfiable {
62: FunType t1 = ft(e1), t2 = ft(e2);
63:
64: Engine.leq(t2.domain(), t1.domain());
65: Engine.leq(t1.codomain(), t2.codomain());
66: }
67:
68: private FunType ft(Element e) {
69: try {
70: return (FunType) ((Monotype) e).equivalent();
71: } catch (ClassCastException ex) {
72: throw new InternalError(e
73: + " was expected to be a functional type, "
74: + " it's a " + e.getClass());
75: }
76: }
77:
78: public String toString() {
79: return "Fun(" + domainArity + ")";
80: }
81:
82: public int domainArity;
83:
84: }
|