Skip to main content
    • Aa
    • Aa

Every bit counts: The binary representation of typed data and programs


We show how the binary encoding and decoding of typed data and typed programs can be understood, programmed and verified with the help of question–answer games. The encoding of a value is determined by the yes/no answers to a sequence of questions about that value; conversely, decoding is the interpretation of binary data as answers to the same question scheme. We introduce a general framework for writing and verifying game-based codecs. We present games in Haskell for structured, recursive, polymorphic and indexed types, building up to a representation of well-typed terms in the simply-typed λ-calculus with polymorphic constants. The framework makes novel use of isomorphisms between types in the definition of games. The definition of isomorphisms together with additional simple properties make it easy to prove that codecs derived from games never encode two distinct values using the same code, never decode two codes to the same value and interpret any bit sequence as a valid code for a value or as a prefix of a valid code. Formal properties of the framework have been proved using the Coq proof assistant.

Linked references
Hide All

This list contains references from the content that can be linked to their source. For a full set of references and notes please see the PDF or HTML where available.

Y. Bertot & P. Casteran (2004) Interactive Theorem Proving and Program Development. Springer-Verlag.

R. Bird & J. Gibbons (2003) Arithmetic coding with folds and unfolds. In Advanced Functional Programming 4, J. Jeuring & S. Peyton Jones (eds), Lecture Notes in Computer Science, vol. 2638. Springer-Verlag, pp. 126.

R. D. Cameron (1988) Source encoding using syntactic information source models. IEEE Trans. Inf. Theory 34 (4), 843850.

K. Claessen & J. Hughes (2000) Quickcheck: A lightweight tool for random testing of Haskell programs. In ICFP '00: Proceedings of the 5th ACM SIGPLAN International Conference on Functional Programming. New York: ACM, pp. 268279.

J. F. Contla (1985) Compact coding of syntactically correct source programs. Softw. Pract. Exper. 15, 625636.

D. Coutts , R. Leshchinskiy & D. Stewart (2007) Stream fusion: From lists to streams to nothing at all. In ICFP '07: Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming. New York: ACM, pp. 315326.

P. Elias (1975) Universal codeword sets and representations of the integers. IEEE Trans. Inf. Theory 21 (2), 197203.

K. Fisher , Y. Mandelbaum & D. Walker (2006) The next 700 data description languages. SIGPLAN Not. 41 (1), 215.

J. Gibbons (2007) Datatype-generic programming. In Datatype-Generic Programming, R. Backhouse , J. Gibbons , R. Hinze & J. Jeuring (eds), LNCS, vol. 4719. Berlin, Heidelberg: Springer, pp. 171.

V. Haldar , C. H. Stork & M. Franz (2002) The source is the proof. In NSPW '02: Proceedings of the 2002 Workshop on New Security Paradigms. New York: ACM, pp. 6973.

D. E. Knuth (1992) Axioms and Hulls, LNCS, vol. 606. Springer-Verlag.

G. C. Necula & P. Lee (1998) The design and implementation of a certifying compiler. In PLDI '98: Proceedings of the ACM SIGPLAN 1998 Conference on Programming Language Design and Implementation. New York: ACM, pp. 333344.

G. C. Necula & S. P. Rahul (2001) Oracle-based checking of untrusted software. In POPL'01: Proceedings of the 28th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. New York: ACM, pp. 142154.

L. Nielsen & F. Henglein (2011) Bit-coded regular expression parsing. In Proceedings of the 5th Int'l Conference on Language and Automata Theory and Applications (LATA), LNCS, vol. 6638. Springer, pp. 402413.

M. H. Palka , K. Claessen , A. Russo & J. Hughes (2011) Testing an optimising compiler by generating random lambda terms. In Proceedings of the 6th International Workshop on Automation of Software Test (AST), AST '11. New York: ACM, pp. 9197.

T. Rendel & K. Ostermann (2010) Invertible syntax descriptions: unifying parsing and pretty printing. SIGPLAN Not. 45, 112.

D. Salomon (2008) A Concise Introduction to Data Compression, Undergraduate Topics in Computer Science. Springer.

M. H. Sørensen & P. Urzyczyn (2006) Lectures on the Curry-Howard Isomorphism (Studies in Logic and the Foundations of Mathematics, Volume 149). New York: Elsevier Science.

Recommend this journal

Email your librarian or administrator to recommend adding this journal to your organisation's collection.

Journal of Functional Programming
  • ISSN: 0956-7968
  • EISSN: 1469-7653
  • URL: /core/journals/journal-of-functional-programming
Please enter your name
Please enter a valid email address
Who would you like to send this to? *


Full text views

Total number of HTML views: 0
Total number of PDF views: 12 *
Loading metrics...

Abstract views

Total abstract views: 79 *
Loading metrics...

* Views captured on Cambridge Core between September 2016 - 29th May 2017. This data will be updated every 24 hours.