Skip to main content
×
×
Home

Ghostbuster: A tool for simplifying and converting GADTs

  • TIMOTHY A. K. ZAKIAN (a1), TREVOR L. MCDONELL (a2), MATTEO CIMINI (a3) and RYAN R. NEWTON (a4)
Abstract

Generalized Algebraic Data Types, or simply GADTs, can encode non-trivial properties in the types of the constructors. Once such properties are encoded in a datatype, however, all code manipulating that datatype must provide proof that it maintains these properties in order to typecheck. In this paper, we take a step toward gradualizing these obligations. We introduce a tool, Ghostbuster, that produces simplified versions of GADTs which elide selected type parameters, thereby weakening the guarantees of the simplified datatype in exchange for reducing the obligations necessary to manipulate it. Like ornaments, these simplified datatypes preserve the recursive structure of the original, but unlike ornaments, we focus on information-preserving bidirectional transformations. Ghostbuster generates type-safe conversion functions between the original and simplified datatypes, which we prove are the identity function when composed. We evaluate a prototype tool for Haskell against thousands of GADTs found on the Hackage package database, generating simpler Haskell'98 datatypes and round-trip conversion functions between the two.

Copyright
References
Hide All
Abadi, M., Cardelli, L., Pierce, B., & Rémy, D. (1995) Dynamic typing in polymorphic languages. J. Funct. Program. 5, 111130.
Abadi, M., Cardelli, L., Pierce, B. & Plotkin, G. (1989) Dynamic typing in a statically-typed language. ACM Trans. Program. Lang. Syst. 13 (2), 237268.
Altenkirch, T. & Reus, B. (1999) Monadic presentation of lambda terms using generalised inductive types. In Computer Science Logic, Flum, J. & Rodriguez-Artalejo, M. (eds). Berlin, Heidelberg: Springer, pp. 453468.
Appel, A. W. (2007) Compiling with Continuations. New York, NY, USA: Cambridge University Press.
Appel, A. W. & Jim, T. (1997) Shrinking lambda expressions in linear time. J. Funct. Program. 7 (5), 515540.
Baars, A. I. & Swierstra, S. D. (2002a) Typing dynamic typing. In ICFP02: International Conference on Functional Programming, pp. 157–166.
Baars, A. I. & Swierstra, S. D. (2002b) Typing dynamic typing. In Proceedings of the 7th ACM SIGPLAN International Conference on Functional Programming, ICFP '02. New York, NY, USA: ACM, pp. 157–166.
Benton, N., Kennedy, A., Lindley, S. & Russo, C. (2005) Shrinking Reductions in sml.net. Berlin, Heidelberg: Springer, pp. 142159.
Bernardy, J.-P., Boespflug, M., Newton, R. R., Peyton, Jones S. & Spiwack, A. (2018) Linear Haskell: Practical linearity in a higher-order polymorphic language. Proc. ACM Program. Lang. 2 (POPL), 5:15:29
Brady, E., McBride, C. & McKinna, J. (2004) Inductive families need not store their indices. In Types for Proofs and Programs, Stefano, B., Mario, C. & Damiani, F. (eds). Berlin, Heidelberg: Springer, pp. 115129.
Casinghino, C., Sjöberg, V. & Weirich, S. (2014) Combining proofs and programs in a dependently typed language. In POPL'14: Principles of Programming Languages, pp. 33–45.
Chakravarty, M. M. T., Keller, G., Lee, S., McDonell, T. L. & Grover, V. (2011) Accelerating Haskell array codes with multicore GPUs. In DAMP'11: Declarative Aspects of Multicore Programming, pp. 3–14.
Chakravarty, M. M. T., Keller, G. & Peyton, Jones S. (2005) Associated type synonyms. In POPL'05: Principles of Programming Languages, pp. 241–253.
Cheney, J. & Hinze, R. (2002) A lightweight implementation of generics and dynamics. In Proceedings of the ACM SIGPLAN Workshop on Haskell, Haskell'02. New York, NY, USA: ACM, pp. 90–104.
Cheney, J. & Hinze, R. (2003) First-Class Phantom Types. Technical Report, Cornell University.
Dagand, P.-E. & McBride, C. (2012) Transporting functions across ornaments. In ICFP'12: International Conference on Functional Programming, pp. 103–114.
Dagand, P.-E., Tabareau, N. & Tanter, É. (2016) Partial type equivalences for verified dependent interoperability. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming, ICFP'16. New York, NY, USA: ACM, pp. 298–310.
Findler, R. B. & Felleisen, M. (2002 October) Contracts for higher-order functions. In Proceedings of the International Conference on Functional Programming, ICFP, pp. 48–59.
Hall, C. V., Hammond, K., Peyton Jones, S. & Wadler, P. L. (1996) Type classes in Haskell. ACM Trans. Program. Lang. Syst. 18 (2), 109138.
Henglein, F. (1994) Dynamic typing: Syntax and proof theory. Sci. Comput. Program. 22 (3), 197230.
Knuth, D. E. (1968) Semantics of context-free languages. Math. Syst. Theory 2 (2), 127145.
Ko, H.-S. & Gibbons, J. (2013) Relational algebraic ornaments. In DTP'13: Dependently-Typed Programming, pp. 37–48.
Leroy, X. & Mauny, M. (1991) Dynamics in ML. In Functional Programming Languages and Computer Architecture, pp. 406–426.
McBride, C. (2005) Type-preserving renaming and substitution [online]. Accessed March 30, 2018. Available at: http://strictlypositive.org/ren-sub.pdf
McBride, C. (2010) Ornamental algebras, algebraic ornaments [online]. Accessed March 30, 2018. Available at: https://personal.cis.strath.ac.uk/conor.mcbride/pub/OAAO/Ornament.pdf
McDonell, T. L., Chakravarty, M. M. T., Keller, G. & Lippmeier, B. (2013) Optimising purely functional GPU programs. In ICFP'13: International Conference on Functional Programming, pp. 49–60.
McDonell, T. L., Chakravarty, M. M. T., Grover, V. & Newton, R. R. (2015) Type-safe runtime code generation: Accelerate to LLVM. In Proceedings of the Haskell Symposium, pp. 201–212.
McDonell, T. L., Zakian, T. A. K., Cimini, M. & Newton, R. R. (2016) Ghostbuster: A tool for simplifying and converting GADTs. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming, ICFP'16. New York, NY, USA: ACM, pp. 338–350.
Ou, X., Tan, G., Mandelbaum, Y. & Walker, D. (2004 August) Dynamic typing with dependent types (extended abstract) In TCS'04: International Conference on Theoretical Computer Science, pp. 437–450.
Peterson, J. & Jones, M. (1993 June) Implementing type classes. In PLDI'93: Programming Language Design and Implementation, pp. 227–236.
PeytonJones, S. Jones, S., Weirich, S., Eisenberg, R. A. & Vytiniotis, D. (2016) A Reflection on Types. Cham: Springer International Publishing, pp. 292317.
Schrijvers, T., PeytonJones, S. Jones, S., Chakravarty, M. M. T. & Sulzmann, M. (2008) Type checking with open type functions. In ICFP'08: International Conference on Functional Programming, pp. 51–62.
Schrijvers, T., Peyton Jones, S., Sulzmann, M. & Vytiniotis, D. (2009a) Complete and decidable type inference for GADTs. In ICFP'09: International Conference on Functional Programming, pp. 341–352.
Schrijvers, T., Peyton Jones, S., Sulzmann, M. & Vytiniotis, D. (2009b) Complete and decidable type inference for GADTs. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP'09. New York, NY, USA: ACM, pp. 341–352.
Sheard, T. & Peyton Jones, S. (2002) Template meta-programming for Haskell. In Proceedings of the Haskell Workshop, pp. 1–16.
Shields, M., Sheard, T. & Peyton Jones, S. (1998) Dynamic typing as staged type inference. In POPL'98: Principles of Programming Languages, pp. 289–302.
Siek, J. G. & Taha, W. (2006) Gradual typing for functional languages. In Proceedings of the Scheme and Functional Programming Workshop, vol. 6, pp. 81–92.
Simonet, V. & Pottier, F. (2007) A constraint-based approach to guarded algebraic data types. ACM Trans. Program. Lang. Syst. 29 (1), 1.
Somogyi, Z., Henderson, F. J. & Conway, T. C. (1995) Mercury, an efficient purely declarative logic programming language. Aust. Comput. Sci. Commun. 17, 499512.
Sulzmann, M. & Wang, M. (2004) A Systematic Translation of Guarded Recursive Data Types to Existential Types. Technical Report, National University of Singapore.
Syme, D., Battocchi, K., Takeda, K., Malayeri, D. & Petricek, T. (2013) Themes in information-rich functional programming for internet-scale data sources. In DDFP'13: Data Driven Functional Programming, pp. 1–4.
Tobin-Hochstadt, S. & Felleisen, M. (2006) Interlanguage migration: From scripts to programs. In Proceedings of the Dynamic Languages Symposium.
Tobin-Hochstadt, S. & Felleisen, M. (2010a) Logical types for untyped languages. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming, ICFP'10. New York, NY, USA: ACM, pp. 117–128.
Tobin-Hochstadt, S. & Felleisen, M. (2010b) Logical types for untyped languages. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming, ICFP'10. New York, NY, USA: ACM, pp. 117–128.
Vytiniotis, D., Peyton Jones, S. & Magalhães, J. P. (2012) Equality proofs and deferred type errors: A compiler pearl. In ICFP'12: International Conference on Functional Programming, pp. 341–352.
Wadler, P. & Findler, R. B. (2009 March) Well-typed programs can't be blamed. In Proceedings of the European Symposium on Programming, ESOP, pp. 1–16.
Weirich, S. (2000) Type-safe cast: (functional pearl). In Proceedings of the 5th ACM SIGPLAN International Conference on Functional Programming, ICFP'00. New York, NY, USA: ACM, pp. 58–67.
Williams, T., Dagand, P.-É. & Rémy, D. (2014) Ornaments in practice. In WGP'14: Workshop on Generic Programming, pp. 15–24.
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? *
×

Metrics

Full text views

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

Abstract views

Total abstract views: 156 *
Loading metrics...

* Views captured on Cambridge Core between 22nd June 2018 - 17th August 2018. This data will be updated every 24 hours.

Ghostbuster: A tool for simplifying and converting GADTs

  • TIMOTHY A. K. ZAKIAN (a1), TREVOR L. MCDONELL (a2), MATTEO CIMINI (a3) and RYAN R. NEWTON (a4)
Submit a response

Discussions

No Discussions have been published for this article.

×

Reply to: Submit a response


Your details


Conflicting interests

Do you have any conflicting interests? *