A Comparative Study of Language Support for Generic Programming - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

A Comparative Study of Language Support for Generic Programming

Description:

... the same level of abstraction, when none dominates the ... Concept: formalization of an abstraction as a set of requirements on a type or set of types ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 21
Provided by: ibm3101
Category:

less

Transcript and Presenter's Notes

Title: A Comparative Study of Language Support for Generic Programming


1
A Comparative Study of Language Support for
Generic Programming
  • Programming Languages Seminar
  • University of Illinois Urbana-Champaign
  • March 10, 2004

2
Overview
  • Generic Programming
  • Features for proper language support
  • Discussion of Findings
  • Questions

3
Generic Programming
  • What is generic programming?
  • Generic programming is a sub-discipline of
    computer science that deals with finding abstract
    representations of efficient algorithms, data
    structures, and other software concepts, and with
    their systematic organization. The goal of
    generic programming is to express algorithms and
    data structures in a broadly adaptable,
    interoperable form that allows their direct use
    in software construction.

4
Key Generic Programming Ideas
  • Expressing algorithms with minimal assumptions
    about data abstractions, and vice versa, thus
    making them as interoperable as possible
  • Lifting of a concrete algorithm to as general a
    level as possible with losing efficiency i.e.,
    the most abstract form such that when specialized
    back to the concrete case the result is just as
    efficient as the original algorithm

5
Key Generic Programming Ideas, cont.
  • When the result of lifting is not general enough
    to cover all uses of an algorithm, additionally
    providing a more general form, but ensuring that
    the most efficient specialized form is
    automatically chosen when applicable
  • Providing more than one generic algorithm for the
    same purpose and at the same level of
    abstraction, when none dominates the others in
    efficiency for all inputs. This introduces the
    necessity to provide sufficiently precise
    characterizations of the domain for which each
    algorithm is the most efficient.

6
Key terminology
  • Concept formalization of an abstraction as a set
    of requirements on a type or set of types
  • Refine incorporating one concept into another
  • Model types that meet the requirements of a
    concept model that concept

7
Features for Proper Language Support
  • Multi-type concepts can multiple types be
    simultaneously constrained?Example in a graph
    type, you may want to constrain the type of the
    nodes and edges at the same time
  • Multiple constraints can multiple constraints be
    placed upon a type parameter?Example

8
Features for Proper Language Support
  • Associated type access can a type be mapped to
    other types easily within a generic
    function?Example If a generic function for a
    graph uses an associated type for a node, how
    easily can this type be specified/used?
  • Retroactive Modeling can a new modeling
    relationship be added easily after a type has
    been defined?Example Once a generic type of
    list has been specified, how easily can it be
    used with other types?

9
Features for Proper Language Support
  • Type aliases are mechanisms available for
    supporting shorter names for types?Example Is
    it possible to give a highly parameterized type
    name a simple type, such as with typedef, or is
    it required to continue using all types in the
    name?
  • Separate compilation are generic functions
    type-checked and compiled independently of their
    use?Example Is the generic function generated
    for each type (C), or can it be compiled
    separately (Java) and then specified where
    needed?

10
Features for Proper Language Support
  • Implicit instantiation can type parameters be
    deduced without requiring explicit syntax for
    their instantiation?Example Once created, is
    it possible to use a function without specifying
    the type parameter information?
  • Consise syntax is the syntax required to compose
    multiple generic layers independent of the scale
    of composition?Example can multiple layers be
    composed without requiring lots of additional
    typing syntax?

11
Findings
12
Support in Various Languages
13
Generics Features
14
Establishing the Modeling Relation
  • Two basic types name conformance and structural
    conformance
  • Name conformance (Java, C, Eiffel, Haskell) an
    explicit declaration links a concrete type to the
    concept it models
  • Structural conformance (C, ML) a type models a
    concept if it meets the structural requirements
    of the concept

15
Establishing the Modeling Relation
  • Named conformance can lead to difficulties with
    retroactive modeling, since the concepts are
    identified in the concrete type
  • This is a problem in Java, C, and Eiffel, but
    not Haskell, since Haskell separately specifies
    modeling and refinement relationships
  • Structural conformance can lead to the problem of
    accidental conformance (rarely), where
    syntactically identical but semantically
    different methods could be used

16
Subtyping is not Modeling or Refinement
  • Constraints on multiple types can be implemented
    using Java
  • However, it is difficult to do this consistently
    using just a subtyping mechanism
  • Often, very verbose constraints are needed, with
    much repetition

17
Access to Associated Types
  • Some languages, like C (through a trait
    mechanism) or ML, provide support for accessing
    associated types easily in the generic function
  • Others make this more difficult, requiring the
    associated types to be specified in each generic
    function

18
Implicit Instantiation Type Aliases
  • Implicit instantiation is required to prevent
    extremely verbose generic function calls
  • Type aliases are required to prevent extremely
    verbose type specifications
  • When these features are not present, type
    declarations and function calls can become very
    painful

19
Lack of type aliases
20
Questions?
Write a Comment
User Comments (0)
About PowerShow.com