Module: internal Synopsis: The definition of singleton types Author: Jonathan Bachrach, Keith Playford Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND //// The singleton type // BOOTED: define ... class ... end; define method initialize (x :: , #key, #all-keys) => () next-method(); initialize-singleton-instance?-function(x); end method; // TODO: figure out how to break the circularity that prevents // us from making this a non-generic function define method singleton (object :: ) => (singleton :: ); make(, object: object) end; define method \= (singleton-1 :: , singleton-2 :: ) => (equal :: ) singleton-1.singleton-object = singleton-2.singleton-object; end method \=; define method limits (s :: ) => (class :: ) s.singleton-object.object-class end method limits; // @@@@@ This assumes we don't have hollow singletons! (If we did, they'd // @@@@@ be another type anyway.) define method type-complete? (t :: ) => (well? :: ) #t end method; define method map-congruency-classes (f :: , t :: ) => () map-congruency-classes(f, object-class(singleton-object(t))) end method; // @@@@@ This assumes we don't have hollow singletons! define method reduce-incomplete-classes (f :: , t :: , ans) => (ans) ans end method; //// Instance? relationships define inline constant initialize-singleton-instance?-function = method (s :: ) => () instance?-iep(s) := simple-method-iep (if (indirect-object?(s.singleton-object)) singleton-value-object-instance? else singleton-pointer-id?-instance? end if); end method; // This is the default instance?-function for singletons. It's just a non-generic version // of uninitialized-instance?-function. define constant singleton-instance? = method (x, s :: ) => (v :: ); initialize-singleton-instance?-function(x); primitive-instance?(x, s) end method; define constant singleton-pointer-id?-instance? = method (x, s :: ) => (v :: ); pointer-id?(x, s.singleton-object) end method; define constant singleton-value-object-instance? = method (x, s :: ) => (v :: ); let o = singleton-object(s); indirect-object?(x) & pointer-id?(indirect-object-class(x), indirect-object-class(o)) & (x = o) end method; //// Subtype? relationships define method subtype? (s1 :: , s2 :: ) => (subtype? :: ) s1.singleton-object == s2.singleton-object end method subtype?; define method subtype? (s :: , t :: ) => (subtype? :: ) instance?(s.singleton-object, t) end method subtype?; define method subtype? (t :: , s :: ) => (subtype? :: ) #f end method subtype?; define method subjunctive-subtype? (s1 :: , s2 :: , scu :: ) => (subtype? :: ) s1.singleton-object == s2.singleton-object end method subjunctive-subtype?; define method subjunctive-subtype? (s :: , t :: , scu :: ) => (subtype? :: ); // It's a subjunctive subtype if the object is an instance of the type // and the class of the object is not being redefined. instance?(s.singleton-object, t) & ( (scu == $empty-subjunctive-class-universe) | ~scu-entry?(s.singleton-object.object-class, scu)) end method subjunctive-subtype?; define method subjunctive-subtype? (t :: , s :: , scu :: ) => (subtype? :: ) #f end method subjunctive-subtype?; define method disjoint-types-1? (t1 :: , t2 :: , scu :: , dep :: ) => (well? :: ) t1.singleton-object ~== t2.singleton-object end method; //define method disjoint-types-1? (t1 :: , t2 :: ) // => (well? :: ) // ~instance?(t1.singleton-object, t2) //end method; //define method disjoint-types-1? (t1 :: , t2 :: ) // => (well? :: ) // ~instance?(t2.singleton-object, t1) //end method; //// Potential instance relationships define method has-instances? (class :: , s :: , scu :: ) => (some? :: , all? :: ); // values(class == s.singleton-object.object-class, #f) // values(scu-entry(class, scu) == s.singleton-object.object-implementation-class, #f) let some? = has-instances?(s.singleton-object.object-class, class, scu); values(some?, #f) end method has-instances?; // eof