## Dimension Inference under Polymorphic Recursion (1995)

Venue: | In Proc. 7th Conf. Functional Programming Languages and Computer Architecture |

Citations: | 9 - 1 self |

### BibTeX

@INPROCEEDINGS{Rittri95dimensioninference,

author = {Mikael Rittri},

title = {Dimension Inference under Polymorphic Recursion},

booktitle = {In Proc. 7th Conf. Functional Programming Languages and Computer Architecture},

year = {1995},

pages = {147--159},

publisher = {ACM Press}

}

### OpenURL

### Abstract

Numeric types can be given polymorphic dimension parameters, in order to avoid dimension errors and unit errors. The most general dimensions can be inferred automatically. It has been observed that polymorphic recursion is more important for the dimensions than for the proper types. We show that, under polymorphic recursion, type inference amounts to syntactic semi-unification of proper types, followed by equational semi-unification of dimensions. Syntactic semi-unification is unfortunately undecidable, although there are procedures that work well in practice, and proper types given by the programmer can be checked. However, the dimensions form a vector space (provided that their exponents are rational numbers). We give a polynomial-time algorithm that decides if a semi-unification problem in a vector space can be solved and, if so, returns a most general semi-unifier. 1 Introduction We will combine three good things as far as possible: dimension types, polymorphic recursion, and aut...

### Citations

936 | A theory of type polymorphism in progra.mming
- Milner
- 1978
(Show Context)
Citation Context ...li correlation :: 8xy: [ (Rhxi; Rhyi) ] ! Rh1li 1.2 Polymorphic recursion Usually, we expect that a function of polymorphic type can be used with any instance of its type. But in Milner's type system =-=[2, 19]-=-, this is not true in expressions that are part of the function's definition (via recursion). Consider the following definition of trapeziform matrices. infixr :. data Trapez ff fi = Naught --- (ff, f... |

704 | Linear Algebra and Its Applications - Strang - 1988 |

358 |
Principal type-schemes for functional programs
- Damas, Milner
- 1982
(Show Context)
Citation Context ...li correlation :: 8xy: [ (Rhxi; Rhyi) ] ! Rh1li 1.2 Polymorphic recursion Usually, we expect that a function of polymorphic type can be used with any instance of its type. But in Milner's type system =-=[2, 19]-=-, this is not true in expressions that are part of the function's definition (via recursion). Consider the following definition of trapeziform matrices. infixr :. data Trapez ff fi = Naught --- (ff, f... |

161 |
Solving equations in abstract algebras: A rulebased survey of unification
- Jouannaud, Kirchner
- 1991
(Show Context)
Citation Context ...quational theory; thus, equational unification is just equation solving in various algebras. Fages and Huet [4] give crisp definitions of some basic concepts; Siekmann [25] and Jouannaud and Kirchner =-=[10]-=- give broad surveys. Definition 1 An E-unification problem is a finite set of pairs of terms. Each pair hs; ti is called an equation and is usually written s = ? E t. A substitution S is an E-unifier ... |

110 |
Elements of Functional Programming
- READE
- 1989
(Show Context)
Citation Context ...kell compiler. 11 However, I have chosen not to change table 1, because it may be more familiar, being similar to the first-order systems in Milner [19] and Henglein [6] and to Reade's implementation =-=[23]-=-. 4.3 On type-schemes and semantic soundness The inference system was designed to make it clear that semi-unification is sufficient for type inference. However, we should show that the inference syste... |

108 |
Unification theory
- Siekmann
- 1989
(Show Context)
Citation Context ...hat terms become equal in some equational theory; thus, equational unification is just equation solving in various algebras. Fages and Huet [4] give crisp definitions of some basic concepts; Siekmann =-=[25]-=- and Jouannaud and Kirchner [10] give broad surveys. Definition 1 An E-unification problem is a finite set of pairs of terms. Each pair hs; ti is called an equation and is usually written s = ? E t. A... |

93 | Polymorphic type schemes and recursive definitions - Mycroft - 1984 |

61 | Polymorphic type inference and abstract data types
- Läufer, Odersky
- 1994
(Show Context)
Citation Context ...], and other examples have been discussed on the ML and Haskell mailing lists. Furthermore, polymorphic recursion becomes much more important when one uses the existential types of Laufer and Odersky =-=[18]-=-. They give an example with a list of composable functions; in order to apply the composition to a value, polymorphic recursion is needed [18, pages 1418-- 1419]. Another example can be found in Prasa... |

55 |
Type reconstruction in the presence of polymorphic recursion
- Kfoury, Tiuryn, et al.
- 1993
(Show Context)
Citation Context ...). Since fstCol is polymorphic, that should be okay, but such polymorphic recursion is not allowed in Milner's type system. The reason is that type inference under polymorphic recursion is equivalent =-=[6, 13]-=- to semi-unification, an undecidable problem [14]; see section 2. However, if the types are given by the programmer, then polymorphic recursion is allowed in Hope, Miranda TM , CAML, and one option of... |

54 |
The undecidability of the semi-unification problem
- Kfoury, Tiuryn, et al.
- 1990
(Show Context)
Citation Context ... but such polymorphic recursion is not allowed in Milner's type system. The reason is that type inference under polymorphic recursion is equivalent [6, 13] to semi-unification, an undecidable problem =-=[14]-=-; see section 2. However, if the types are given by the programmer, then polymorphic recursion is allowed in Hope, Miranda TM , CAML, and one option of the Chalmers Haskell compiler (hbc -fuse-restr),... |

54 |
Foundations of measurement (Vol
- Krantz, Luce, et al.
- 1971
(Show Context)
Citation Context ...CA'95-6/95/La Jolla, California c fl1995 ACM . . . 1.1 Dimension types Most type systems allow programmers to make dimension errors, like adding metres to kilograms. (I assume that dimension checking =-=[3, 15, 28]-=- is familiar.) Such errors can be prevented by giving dimension parameters to the numeric types. There have been several suggestions, but the dimensions are usually monomorphic; most of these suggesti... |

30 | Dimension types
- Kennedy
- 1994
(Show Context)
Citation Context ...e. Later, Wand and O'Keefe [27] realised that polymorphic dimensions can be inferred in a way that is analogous to Milner's algorithm. This was re-discovered independently by Goubault [5] and Kennedy =-=[11]-=-; they also made implementations (for ML). The type systems of the last three papers are similar. To express polymorphism, you need variables in dimensions. Wand and O'Keefe use variables that range o... |

24 |
An Ada Package for Dimensional Analysis
- Hilfinger
- 1988
(Show Context)
Citation Context ...ism as my table 1 after all (apart from the polymorphic recursion). A full account of these matters will appear in Kennedy's thesis [12]. 5 Integers versus rational numbers Kennedy [11] and Hilfinger =-=[8]-=- believe that integers suffice for dimension exponents, but most other authors allow rational numbers. A hundred years ago, integers would have failed, because it was common not to use new base dimens... |

20 | Programming with broadcasts - Prasad - 1993 |

19 |
Complete Sets of Unifiers and Matchers in Equational Theories
- Fages, Huet
- 1986
(Show Context)
Citation Context ...nification, you are trying to find values for variables so that terms become equal in some equational theory; thus, equational unification is just equation solving in various algebras. Fages and Huet =-=[4]-=- give crisp definitions of some basic concepts; Siekmann [25] and Jouannaud and Kirchner [10] give broad surveys. Definition 1 An E-unification problem is a finite set of pairs of terms. Each pair hs;... |

18 | Automatic Dimensional Inference
- Wand, O’Keefe
- 1991
(Show Context)
Citation Context ...these suggestions are reviewed in [5]. House [9] was the first to suggest a type system with polymorphic dimensions (for Pascal), but did not discuss automatic type inference. Later, Wand and O'Keefe =-=[27]-=- realised that polymorphic dimensions can be inferred in a way that is analogous to Milner's algorithm. This was re-discovered independently by Goubault [5] and Kennedy [11]; they also made implementa... |

17 |
A Proposal for an Extended Form of Type Checking of Expressions
- House
- 1983
(Show Context)
Citation Context ...be prevented by giving dimension parameters to the numeric types. There have been several suggestions, but the dimensions are usually monomorphic; most of these suggestions are reviewed in [5]. House =-=[9]-=- was the first to suggest a type system with polymorphic dimensions (for Pascal), but did not discuss automatic type inference. Later, Wand and O'Keefe [27] realised that polymorphic dimensions can be... |

11 |
Note on the Existence of Most General Semi-unifiers
- Baaz
- 1993
(Show Context)
Citation Context ...lgebra, and the (semi-)unifiers have to make dimensions equal in an equational theory. This section reviews these algebraic concepts, and discusses how Baaz's procedure for syntactic semi-unification =-=[1]-=- can be extended to equational semi-unification. 2.1 Terms, substitutions, and equivalence Terms are built in the familiar way from a countably infinite set of variables and a finite set of function s... |

9 |
Abelian group unification algorithms for elementary terms
- Lankford, Butler, et al.
- 1984
(Show Context)
Citation Context ...we wanted to compare over z as well, we would find that fx := z; y := zg 66 fx;y;zg fx := yg. Unification is unitary in the free term algebra (syntactic unification), in Abelian groups with constants =-=[16]-=-, in vector spaces with constants, and in a few other equational theories [10, 25]. 2.3 Semi-unification Semi-unification is a combination of unification and matching. The applications of syntactic se... |

8 |
Type inference with polymorphic recursion. ACM transactions on programming languages and systems
- Henglein
- 1993
(Show Context)
Citation Context ...m for semi-unification in the equational theory for vector spaces. Section 4 motivates that the algorithm can be used to infer dimensions under polymorphic recursion; the reasoning mirrors Henglein's =-=[6]-=-. Section 5 discusses the relative merits of integers and rational numbers as dimension exponents; the integers make the dimensions form a freely generated Abelian group, whereas the rational numbers ... |

5 | Inference d’unites physiques en ML
- Goubault
- 1994
(Show Context)
Citation Context ...errors can be prevented by giving dimension parameters to the numeric types. There have been several suggestions, but the dimensions are usually monomorphic; most of these suggestions are reviewed in =-=[5]-=-. House [9] was the first to suggest a type system with polymorphic dimensions (for Pascal), but did not discuss automatic type inference. Later, Wand and O'Keefe [27] realised that polymorphic dimens... |

3 | Semi-unification of two terms in Abelian groups
- Rittri
- 1994
(Show Context)
Citation Context ...ching. The applications of syntactic semi-unification are surveyed by Kfoury et al. [14], but I have not found any literature on equational semi-unification, apart from my own paper on Abelian groups =-=[24]-=-. If you let E = ; in my definitions, you get syntactic semi-unification (since =E is then syntactic equality). Definition 3 An E-semi-unification problem is a finite set of boxes, which can be number... |

2 |
The mathematics of physical quantities. Part II. Quantity structures and dimensional analysis
- Whitney
- 1968
(Show Context)
Citation Context ...CA'95-6/95/La Jolla, California c fl1995 ACM . . . 1.1 Dimension types Most type systems allow programmers to make dimension errors, like adding metres to kilograms. (I assume that dimension checking =-=[3, 15, 28]-=- is familiar.) Such errors can be prevented by giving dimension parameters to the numeric types. There have been several suggestions, but the dimensions are usually monomorphic; most of these suggesti... |

1 |
On the nature of dimensions
- Ellis
- 1964
(Show Context)
Citation Context ...CA'95-6/95/La Jolla, California c fl1995 ACM . . . 1.1 Dimension types Most type systems allow programmers to make dimension errors, like adding metres to kilograms. (I assume that dimension checking =-=[3, 15, 28]-=- is familiar.) Such errors can be prevented by giving dimension parameters to the numeric types. There have been several suggestions, but the dimensions are usually monomorphic; most of these suggesti... |

1 |
Physical Dimension and Programming Languages
- Kennedy
- 1995
(Show Context)
Citation Context ...efore, the type systems in [5, 11, 27] should give as much polymorphism as my table 1 after all (apart from the polymorphic recursion). A full account of these matters will appear in Kennedy's thesis =-=[12]-=-. 5 Integers versus rational numbers Kennedy [11] and Hilfinger [8] believe that integers suffice for dimension exponents, but most other authors allow rational numbers. A hundred years ago, integers ... |

1 |
Neumann (ed.) Risks to the public in computer systems
- G
- 1985
(Show Context)
Citation Context ...more peculiar units: yard = 0.9144 * metre mile = 1760 * yard The space shuttle Discovery once flew upside down, because a length measured in feet was given to a computer that expected nautical miles =-=[21]-=-. Even though that was a unit error rather than a dimension error, it would have been prevented by dimension types, since some unit must be given explicitly to construct a length. Most transcendental ... |