A simple and powerful type system for programming languages

  • Authors:
  • Ronald F. Ayres

  • Affiliations:
  • 2807 Pacific Avenue, Venice, CA

  • Venue:
  • Journal of Systems and Software - Special issue: Applications of statistics in software engineering
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

A type system serves to guarantee that programs mix data of distinct types only as allowed by programmer declared rules. For example, a function declaration corresponds to one of these rules, providing a way to mix data of distinct types, possibly producing data of another type as a result. A type system also discovers the type of each (sub)expression throughout a program. This paper introduces a type system where types are parts of speech, and all relations among types are represented by a grammar, a grammar whose rules are written in terms of the types. In order to resolve types, i.e., discover which type each (sub)expression is, the type grammar may be used to parse a given program, as a second pass. A brief, Polish postfix programming language rich in types is presented, called the type grammar, as well as a way to translate down from a more natural syntax. We show how to extend the type grammar with new rules based on program declarations. By parsing with this postfix type grammar, unrestricted overloading (more powerful than Java's) and unrestricted programmer-defined coercions (in some ways more powerful than multiple inheritance) may be implemented and understood in a straightforward manner. To realize these, a powerful parser like Earley's efficient context-free parser, or others, which tolerate ambiguity efficiently, are required. We conclude by showing how a pair of coercions, in a cycle, proves useful.