This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: records


Jost Boekemeier wrote:

> A generic type has its own state and behaviour.  But you can't 
> create  instances from this type.  Instead you must combine the 
> generic type with a concrete type (the parameter).  For example 
> the scheme `display' function is generic.  When you pass an 
> integer type, it will display this integer, when you pass it a 
> string type, it will display the string.

In C++/Eiffel terminology, scheme `display' is, or at least appears to
be polymorphic. From the OO FAQ...

"Parametric polymorphism is obtained when a function works uniformly on
a range of types; these types normally exhibit some common structure. 
Ad-hoc polymorphism is obtained when a function works, or appears to
work, on several different types (which may not exhibit a common
structure) and may behave in unrelated ways for each type." 
 
> On the other hand we have polymorphism.  Polymorphism means 
> that a type derives from a super-type. 

No, polymorphism means that references can refer to more than one type.
From Meyer " In object-oriented programming, this refers to the ability
of an entity to refer at run-time to instances of various classes.". In
something like Java it might mean that two objects implement a
particular interface, but it doesn't mean they inherit from a common
base class.
 
> In other words: polymorphism means that one bit of code can be
> expanded to work on multiple classes by using interitance.  And
> genericity means that the generic type dispatches on the type
> of its parameter (or parameters).

From the OO FAQ...
"Parametric polymorphism is referred to as generics. Generics can be
syntactic, where each instantiation creates a
specialized version of the code allowing fast running execution, but in
a "true polymorphic system", only a single implementation is used.".

> > neither generics nor inheritance, yet it is possible to 
> support both without extending the language.
> 
> (+ 1 2)
> (+ 1.0 2.0)
> 
> The function `+' is generic.

Scheme has a couple of built-in polymorphic functions, but it doesn't
have a generic system available for the programmer to use. But you can
build one due to the expressiveness of the language. So Meyer must be
wrong (if he made the blanket statement you suggest).
 
> > genericity in the Eiffel sense is a non-issue in scheme 
> > because it is
> > not statically typed. Only static typed languages care about 
> > this.
> 
> I think it's the other way round.  You can't support 
> inheritance without a explicit type system. (*)

Vanilla Scheme doesn't have an extensible type system. But you can build
an extensible type system using Scheme primitives.

The reason I say eiffel generics are irrevant for Scheme is because
eiffel generics are used to do things like build collection classes that
are type safe. 

From the Eiffel manual...
"Without genericity, it would be impossible to obtain static type
checking in arealistic object-oriented language.". But Scheme doesn't
care about static type checking. Generics (according to the Eiffel
version of the word) has little relevance.
 
> > > Eiffel supports inheritance *and* (as a special
> > > case) a generic type so that it is not necessary to emulate it.
> >
> > Not sure what you mean by Eiffel's special case.
> 
> Eiffel supports only unconstrained genericity, see his stack 
> example in OOSC.  So it is not necessary to create a empty 
> class to derive your parameter from.

Eiffel has supported constrained genericity as long as I can remember.
See http://www.eiffel.com/doc/manuals/language/intro/geninh.maker.html

-- 
Chris Bitmead
mailto:chris@tech.com.au

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]