Classes or Types? 
Author Message
 Classes or Types?

This may sound a silly question, but does Dylan have classes or types?

Take a class/type definition:
    define class <apple> (<fruit>)
    end class <apple>;

and a function:
    define method peel (<apple>)
        end method peel;

Bertrand Meyer says in OOSC2 (section 7.3):
    "In non-O-O approaches, the module and type concepts remain distinct.
        The most remarkable property of the notion of class is that it subsumes
        these two concepts, merging them into a single linguistic construct."
and also (section 7.7):
    "The facilities provided by class [X], viewed as a module, are precisely
        the operations available on instances of class [X], viewed as a type."

Paraphrasing somewhat, I take it to mean that a class is a type together
with all the methods that can be applied to that type.  I can easily see
that in the case of C++ and similar languages, but Dylan?  As far as I
know, there is no connection between the definition of <apple> and the
method peel; <apple> cannot 'know' what can be done to it.

Is <apple> therefore a type, not a class?  Thoughts anyone?

Glenn (in a class of his own)



Sat, 09 Mar 2002 03:00:00 GMT  
 Classes or Types?

 Glenn> This may sound a silly question, but does Dylan have classes or types?

A class is a special kind of type -- in particular a class has
superclasses.

In the DRM (which is online and also distributed with HD), you will
see that <type> is a subclass of <object>, and <class> and <singleton>
are subclasses of <type>.

The ways you can create types are:
  (1) define class foo (super1 super2 ...) slot-specs end class;
      which is shorthand for
        define foo = make(<class>, superclasses: list(super1, super2, ...),
                          slots: ...);
  (2) singleton(obj),
      which is shorthand for make(<singleton>, object: obj);
  (3) type-union(type1, type2, ...), and
  (4) limited(class ...) -- creates a limited subtype of class (use
      of limited comes with lots of caveats)

At runtime, every object is an instance of some class.
Methods specialize generic functions using types.
Let-bindings constrain their values using types.

 Glenn> Take a class/type definition:
 Glenn>     define class <apple> (<fruit>)
 Glenn>     end class <apple>;

 Glenn> and a function:
 Glenn>     define method peel (<apple>)
 Glenn>      end method peel;

 Glenn> Bertrand Meyer says in OOSC2 (section 7.3):
 Glenn>     "In non-O-O approaches, the module and type concepts remain distinct.
 Glenn>      The most remarkable property of the notion of class is that it subsumes
 Glenn>      these two concepts, merging them into a single linguistic construct."
 Glenn> and also (section 7.7):
 Glenn>     "The facilities provided by class [X], viewed as a module, are precisely
 Glenn>      the operations available on instances of class [X], viewed as a type."

 Glenn> Paraphrasing somewhat, I take it to mean that a class is a type together
 Glenn> with all the methods that can be applied to that type.  I can easily see
 Glenn> that in the case of C++ and similar languages, but Dylan?  As far as I
 Glenn> know, there is no connection between the definition of <apple> and the
 Glenn> method peel; <apple> cannot 'know' what can be done to it.

 Glenn> Is <apple> therefore a type, not a class?  Thoughts anyone?

It looks to me like you are thinking in terms of single dispatch, or
message-passing style, aka "class-centric".  In a multi-method
dispatch system such as Dylan, methods are not "part of" a class --
they are part of a generic function.  Thinking in terms of generic
functions, then, we can say about your example,

  the "peel" generic function has a method defined on class <apple>.

Indeed, you can find out what methods are defined for a generic
function by querying the generic function with the
"generic-function-methods" function.

Furthermore, <apple> is a class, and all classes are types.

Hope this helps.
--

Sullivan  http://www.ai.mit.edu/~gregs/



Sun, 10 Mar 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Conflict Between Class-as-Module and Class-as-Type (long)

2. type classes and type constraints

3. Preview Class and Type Inconsistency

4. deallocating class wide types

5. access on function returning a class wide type

6. Copying by dispatching on remote access to class wide types

7. hash tables and class-wide types as fields in a record

8. ambiguities for class wide types

9. Generics and class-wide types

10. generic formal object of class-wide type

11. class instance type comparisons, like isa()

12. The difference between __class__ and type?

 

 
Powered by phpBB® Forum Software