This paper describes practical programming with types parameterized by numbers: e.g., an array type parameterized by the array’s size or a modular group type Zn parameterized by the modulus. An attempt to add, for example, two integers of different moduli should result in a compile-time error with a clear error message. Number-parameterized types let the programmer capture more invariants through types and eliminate some run-time checks. We review several encodings of the numeric parameter but concentrate on the phantom type representation of a sequence of decimal digits. The decimal encoding makes programming with number-parameterized types convenient and error messages more comprehensible. We implement arithmetic on decimal numberparameterized types, which lets us statically typecheck operations such as array concatenation. Overall we demonstrate a practical dependent-type-like system that is just a Haskell library. The basics of the number-parameterized types are written in Haskell98.
[1]
Frank Pfenning,et al.
Eliminating array bound checking through dependent types
,
1998,
PLDI.
[2]
Frank Pfenning,et al.
Dependent types in practical programming
,
1999,
POPL '99.
[3]
Todd L. Veldhuizen,et al.
Arrays in Blitz++
,
1998,
ISCOPE.
[4]
Conor McBride.
Faking it: Simulating dependent types in Haskell
,
2002,
J. Funct. Program..
[5]
Chris Okasaki,et al.
From fast exponentiation to square matrices: an adventure in types
,
1999,
ICFP '99.
[6]
Matthias Blume.
No-Longer-Foreign: Teaching an ML compiler to speak C "natively"
,
2001,
Electron. Notes Theor. Comput. Sci..
[7]
Dietmar Kreye,et al.
A Compilation Scheme for a Hierarchy of Array Types
,
2001,
IFL.
[8]
Lennart Augustsson,et al.
Cayenne—a language with dependent types
,
1998,
ICFP '98.