From fast exponentiation to square matrices: An adventure in types

Authors
Citation
C. Okasaki, From fast exponentiation to square matrices: An adventure in types, ACM SIGPL N, 34(9), 1999, pp. 28-34
Citations number
11
Categorie Soggetti
Computer Science & Engineering
Journal title
ACM SIGPLAN NOTICES
ISSN journal
15232867 → ACNP
Volume
34
Issue
9
Year of publication
1999
Pages
28 - 34
Database
ISI
SICI code
1523-2867(199909)34:9<28:FFETSM>2.0.ZU;2-S
Abstract
Square matrices serve as an interesting case study in functional programmin g. Common representations, such as lists of lists, are both inefficient-at least for access to individual elements-and error-prone, because the compil er cannot enforce "squareness". Switching to a typical balanced-tree repres entation solves the first problem, but not the second. We develop a represe ntation that solves both problems: it offers logarithmic access to each ind ividual element and it captures the shape invariants in the type, where the y can be checked by the compiler. One interesting feature of our solution i s that it translates the well-known fast exponentiation algorithm to the le vel of types. Our implementation also provides a stress test for today's ad vanced type systems-it uses nested types, polymorphic recursion, higher-ord er kinds, and rank-2 polymorphism.