John Reynolds Fable On Types

From http://www.andrew.cmu.edu/user/cebrown/notes/reynolds83.html

"Reynolds presents a fable in which two professors define the complex numbers in different ways (<a,b> for a+bi vs. <r,t> for r(cos(t)+isin(t))) and define the primitive operations (and prove the basic properties of these operations). Then, the two professors classes get switched, but there is no confusion because the two professors always work at the proper level of abstraction using the basic properties of the complex numbers and the primitive operations without referencing the definition. The moral is that: "Type structure is a syntactic discipline for enforcing levels of abstraction." Instead of talking about "the" complex numbers, we should talk about a type "Complex" which can be realized in different but related ways."

(Note: The word "fable" in the title is used in the sense of "a short story devised to convey some useful lesson", not "a fictitious narrative or statement" or "a fiction invented to deceive" (definitions from OED). The point of the story is to show that TypesAreAnAbstractionOfReality, not to imply that TypeTheory is somehow false or useless.)


This justifies the level of abstraction. Imagine the two professors were two programmers that worked in a statically typed language, and worked not on theorems but on algorithms. By declaring that the variables on which they operate were of a type "Complex", by that they declared the abstract contract between the provider of the concrete complex numbers or set of numbers and the writer of the algorithm. That contract may have included the primitive operation on type. Such example of statically typed syntactic contracts are Java interfaces, ML parameterized modules, Haskell TypeClasses.

Thus we have a type as an abstraction. Complex does not represent a concrete set of bits, but any opaque set of bits that comes also with the associated operations, therefore it is a more abstract level from the level at which the algorithm (or the theorem prover) manipulated a concrete representation of Complex, say where the first 8 bytes represented the double representation of "X" and the next 8 bytes represented the double representation of Y from X+Yi. It is a syntactic tool because in a statically typed universe, syntactically, once the first professor promised to write the theorem generically against complex types, he would have been prevented by the syntactic analyzer (type checker) even he wanted to revert with a slight of hand, back to the X + iY notation. Therefore it enforces a level of abstraction, you can't go back once you promise that you write your algorithm using a specified abstraction.

That's the justification for the simple definition in WhatAreTypes.

That is a description of a typical usage of types, not a definition. It does not conflict with AlternativeTypeDefinitions, or at least "side flag theory". --top


Why the use of "syntax"? What if one is using a run-time engine directly? No syntax. The run-time engine for strong-typed language still has it's typing system. Nor is it a very readable definition. "Abstraction" is too vague a word to use in a precise-intended definition. -- top

Why the use of "syntax"? Because by the time syntax expression are transformed into run-time values the enforcement can take place (like in Smalltalk and Lisp) but is no longer considered a tool for abstraction it's a tool strictly for enforcement of invariants in the run-time engine, they remain a tool for abstraction even in Lisp but it's strictly in the head of the programmer and maybe in the documentation. They are no longer tool in the language as the language does not see them, they do not exist as an element in the language. As opposed to DynamicTyping in StaticTyping types and type definitions are an important element in the language. DynamicTyping bet is that programmer's head is a good enough tool to operate on types without any support from the language. Dynamic typing programmers (that would include me, on occasions) still think in terms of types as abstraction, long before the runtime checking happens, but it's like Las Vegas commercials: "what happens here, stays here". The runtime checking (it's not really a tun-time type system, it's a runtime checking system that ensures that the VM does not go kaboom as result of an error, and nothing else) only serves as a safety net in case something goes wrong, but does not help enforce that the type abstractions are used correctly, so when the abstractions are used incorrectly it helps limit the damage.

"Abstraction" has a well defined meaning in English language and only you have problems with it.


A trivial yet familiar to everyone example when a sorting algorithm in Java sorts elements that are characterized as "Comparable", "Comparable" stands in as an abstraction for (string, Integer, Date, etc), therefore the sorting algorithm is no longer specified in terms of the concrete element but in terms of an "abstraction" that hides the irrelevant details (like the layout of strings in memory) and presents to the programmer only the traits that are essential to the sort function, i.e. the compare operator. That matches the definition in the English dictionary: to abstract is to take away irrelevant details, and to talk about some set without referring to concrete elements but to relevant properties thereof.

This is just saying that the elements must answer certain messages as a minimum requirement to be usable within a given framework. A declarative way to achieve something similar to that is that some things must provide a string representation (ASCII or Unicode) by which they are compared. I sometimes do this in database-centric systems that don't offer or connect with a "comparable" behavior interface. Part of the PowerOfPlainText.


EditText of this page (last edited November 2, 2006) or FindPage with title or text search