Abstract
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 for structured, recursive, polymorphic, and indexed types, building up to a representation of well-typed terms in the simply-typed λ-calculus. 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.
Supplemental Material
- }}Y. Bertot and P. Casteran. Interactive Theorem Proving and Program Development. Springer-Verlag, 2004. Google Scholar
Digital Library
- }}R. Bird and J. Gibbons. Arithmetic coding with folds and unfolds. In J. Jeuring and S. Peyton Jones, editors, Advanced Functional Programming 4, volume 2638 of Lecture Notes in Computer Science, pages 1--26. Springer-Verlag, 2003.Google Scholar
- }}J. Cheney. Statistical models for term compression. In DCC '00: Proceedings of the Conference on Data Compression, page 550, Washington, DC, USA, 2000. IEEE Computer Society. Google Scholar
Digital Library
- }}K. Claessen and J. Hughes. Quickcheck: a lightweight tool for random testing of Haskell programs. In ICFP '00: Proceedings of the fifth ACM SIGPLAN International Conference on Functional Programming, pages 268--279, New York, NY, USA, 2000. ACM. Google Scholar
Digital Library
- }}D. Coutts, R. Leshchinskiy, and D. Stewart. Stream fusion: from lists to streams to nothing at all. In ICFP '07: Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming, pages 315--326, New York, NY, USA, 2007. ACM. Google Scholar
Digital Library
- }}J. Duan, J. Hurd, G. Li, S. Owens, K. Slind, and J. Zhang. Functional correctness proofs of encryption algorithms. In Logic for Programming, Artificial Intelligence and Reasoning (LPAR), volume 3835 of LNCS, pages 519--533. Springer, 2005. Google Scholar
Digital Library
- }}ECMA. Standard {ECMA-335}: Common language infrastructure (CLI), 2006.Google Scholar
- }}P. Elias. Universal codeword sets and representations of the integers. IEEE Transactions on Information Theory, 21(2):197--203, 1975.Google Scholar
Digital Library
- }}K. Fisher, Y. Mandelbaum, and D. Walker. The next 700 data description languages. SIGPLAN Not., 41(1):2--15, 2006. Google Scholar
Digital Library
- }}M. Franz, V. Haldar, C. Krintz, and C. H. Stork. Tamper-proof annotations by construction. Technical Report 02-10, Dept of Information and Computer Science, University of California, Irvine, March 2002.Google Scholar
- }}N. Ghani, P. Hancock, and D. Pattinson. Representations of stream processors using nested fixed points. Logical Methods in Computer Science, 5(3), 2009.Google Scholar
- }}J. Gibbons. Datatype-generic programming. In R. Backhouse, J. Gibbons, R. Hinze, and J. euring, editors, Datatype-Generic Programming, volume 4719 of LNCS, chapter 1, pages 1--71. Springer, Berlin, Heidelberg, 2007. Google Scholar
Digital Library
- }}V. Haldar, C. H. Stork, and M. Franz. The source is the proof. In NSPW '02: Proceedings of the 2002 workshop on New security paradigms, pages 69--73, New York, NY, USA, 2002. ACM. Google Scholar
Digital Library
- }}R. Hinze, J. Jeuring, and A. Löh. Comparing approaches to generic programming in Haskell. In Spring School on Datatype-Generic Programming, 2006. Google Scholar
Digital Library
- }}S. Holdermans, J. Jeuring, A. Löh, and A. Rodriguez. Generic views on data types. In In T. Uustalu, editor, Proceedings of the 8th International Conference on Mathematics of Program Construction, MPC'06, volume 4014 of LNCS, pages 209--234. Springer, 2006. Google Scholar
Digital Library
- }}A. J. Kennedy. Functional Pearl: Pickler Combinators. Journal of Functional Programming, 14(6):727--739, October 2004. Google Scholar
Digital Library
- }}G. C. Necula and P. Lee. The design and implementation of a certifying compiler. In PLDI '98: Proceedings of the ACM SIGPLAN 1998 Conference on Programming Language Design and Implementation, pages 333--344, New York, NY, USA, 1998. ACM. Google Scholar
Digital Library
- }}G. C. Necula and S. P. Rahul. Oracle-based checking of untrusted software. In POPL '01: Proceedings of the 28th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 142--154, New York, NY, USA, 2001. ACM. Google Scholar
Digital Library
- }}D. Salomon. A Concise Introduction to Data Compression. Undergraduate Topics in Computer Science. Springer, 2008. Google Scholar
Digital Library
- }}M. H. Sørensen and P. Urzyczyn. Lectures on the Curry-Howard Isomorphism, Volume 149 (Studies in Logic and the Foundations of Mathematics). Elsevier Science Inc., New York, NY, USA, 2006. Google Scholar
Digital Library
- }}M. Sozeau. Subset coercions in Coq. In Selected papers from the International Workshop on Types for Proofs and Programs (TYPES '06), pages 237--252. Springer, 2006. Google Scholar
Digital Library
- }}M. Sulzmann, M. Chakravarty, and S. Peyton Jones. System F with type equality coercions. In ACM Workshop on Types in Language Design and Implementation (TLDI). ACM, 2007. Google Scholar
Digital Library
Index Terms
Functional pearl: every bit counts
Recommendations
Functional pearl: every bit counts
ICFP '10: Proceedings of the 15th ACM SIGPLAN international conference on Functional programmingWe 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 ...
Type-FUNCTIONAL PEARL safe cast
Comparing two types for equality is an essential ingredient for an implementation of dynamic types. Once equality has been established, it is safe to cast a value from one type to another. In a language with run-time type analysis, implementing such a ...
Functional pearl: implicit configurations--or, type classes reflect the values of types
Haskell '04: Proceedings of the 2004 ACM SIGPLAN workshop on HaskellThe configurations problem is to propagate run-time preferences throughout a program, allowing multiple concurrent configuration sets to coexist safely under statically guaranteed separation. This problem is common in all software systems, but ...







Comments