skip to main content
10.1145/3609024.3609412acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Shape-Constrained Array Programming with Size-Dependent Types

Published: 31 August 2023 Publication History

Abstract

We present a dependent type system for enforcing array-size consistency in an ML-style functional array language. Our goal is to enforce shape-consistency at compile time and allow nontrivial transformations on array shapes, without the complexity such features tend to introduce in dependently typed languages. Sizes can be arbitrary expressions and size equality is purely syntactical, which fits naturally within a scheme that interprets size-polymorphic functions as having implicit arguments. When non-syntactical equalities are needed, we provide dynamic checking. In contrast to other dependently typed languages, we automate the book-keeping involved in tracking existential sizes, such as when filtering arrays. We formalise a large subset of the presented type system and prove it sound. We also discuss how to adapt the type system for a real implementation, including type inference, within the Futhark programming language.

References

[1]
Ana Bove, Peter Dybjer, and Ulf Norell. 2009. A Brief Overview of Agda-A Functional Language with Dependent Types. In TPHOLs. 5674, 73–78. https://doi.org/10.1007/978-3-642-03359-9_6
[2]
Edwin Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of functional programming, 23, 5 (2013), 552–593. https://doi.org/10.1017/S095679681300018X
[3]
Edwin Brady. 2021. Idris 2: Quantitative type theory in practice. arXiv preprint arXiv:2104.00480, https://doi.org/10.48550/arXiv.2104.00480
[4]
Kevin Donnelly and Hongwei Xi. 2007. A Formalization of Strong Normalization for Simply-Typed Lambda-Calculus and System F. Electronic Notes in Theoretical Computer Science, 174, 5 (2007), 109–125. issn:1571-0661 https://doi.org/10.1016/j.entcs.2007.01.021 Proceedings of the First International Workshop on Logical Frameworks and Meta-Languages: Theory and Practice (LFMTP 2006)
[5]
Martin Elsman and Martin Dybdal. 2014. Compiling a Subset of APL Into a Typed Intermediate Language. In Proceedings of ACM SIGPLAN International Workshop on Libraries, Languages, and Compilers for Array Programming (ARRAY’14). Association for Computing Machinery, New York, NY, USA. 101–106. isbn:9781450329378 https://doi.org/10.1145/2627373.2627390
[6]
Martin Elsman, Troels Henriksen, Danil Annenkov, and Cosmin E. Oancea. 2018. Static Interpretation of Higher-Order Modules in Futhark: Functional GPU Programming in the Large. Proc. ACM Program. Lang., 2, ICFP (2018), Article 97, jul, 30 pages. https://doi.org/10.1145/3236792
[7]
Jeremy Gibbons. 2016. APLicative Programming with Naperian Functors (Extended Abstract). In Proceedings of the 1st International Workshop on Type-Driven Development (TyDe 2016). Association for Computing Machinery, New York, NY, USA. 13–14. isbn:9781450344357 https://doi.org/10.1145/2976022.2976023
[8]
Jean Yves Girard. 1971. Interpretation Fonctionnelle et Elimination des Coupures de l’Arithmetique d’Ordre Superieur. In Proceedings of the Second Scandinavian Logic Symposium. North-Holland, 63–92.
[9]
Troels Henriksen. 2021. Bounds Checking on GPU. International Journal of Parallel Programming, 49, 6 (2021), 761–775. isbn:1573-7640 https://doi.org/10.1007/s10766-021-00703-4
[10]
Troels Henriksen, Martin Dybdal, Henrik Urms, Anna Sofie Kiehn, Daniel Gavin, Hjalte Abelskov, Martin Elsman, and Cosmin Oancea. 2016. APL on GPUs: A TAIL from the Past, Scribbled in Futhark. In Proceedings of the 5th International Workshop on Functional High-Performance Computing (FHPC 2016). Association for Computing Machinery, New York, NY, USA. 38–43. isbn:9781450344333 https://doi.org/10.1145/2975991.2975997
[11]
Troels Henriksen and Martin Elsman. 2021. Towards Size-Dependent Types for Array Programming. In Proceedings of the 7th ACM SIGPLAN International Workshop on Libraries, Languages and Compilers for Array Programming (ARRAY 2021). Association for Computing Machinery, New York, NY, USA. 1–14. isbn:9781450384667 https://doi.org/10.1145/3460944.3464310
[12]
Troels Henriksen, Niels G. W. Serup, Martin Elsman, Fritz Henglein, and Cosmin E. Oancea. 2017. Futhark: Purely Functional GPU-programming with Nested Parallelism and In-place Array Updates. In Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2017). ACM, New York, NY, USA. 556–571. isbn:978-1-4503-4988-8 https://doi.org/10.1145/3062341.3062354
[13]
Anders Kiel Hovgaard, Troels Henriksen, and Martin Elsman. 2019. High-Performance Defunctionalisation in Futhark. In Trends in Functional Programming, Michał Pał ka and Magnus Myreen (Eds.). Springer International Publishing, Cham. 136–156. isbn:978-3-030-18506-0 https://doi.org/10.1007/978-3-030-18506-0_7
[14]
C.Barry Jay. 1995. A semantics for shape. Science of Computer Programming, 25, 2 (1995), 251–283. issn:0167-6423 https://doi.org/10.1016/0167-6423(95)00015-1 Selected Papers of ESOP’94, the 5th European Symposium on Programming
[15]
C.B. Jay. 1999. Denotational Semantics of Shape:: Past, Present and Future. Electronic Notes in Theoretical Computer Science, 20 (1999), 320–333. issn:1571-0661 https://doi.org/10.1016/S1571-0661(04)80081-1 MFPS XV, Mathematical Foundations of Progamming Semantics, Fifteenth Conference
[16]
Marc Pouzet Jean-Louis Colaço, Baptiste Pauget. 2023. Polymorphic Types with Polynomial Sizes. In Proceedings of the 9th ACM SIGPLAN International Workshop on Libraries, Languages and Compilers for Array Programming (ARRAY 2023). Association for Computing Machinery, New York, NY, USA. https://doi.org/10.1145/3589246.3595372
[17]
Robin Milner. 1978. A theory of type polymorphism in programming. J. Comput. System Sci., 17, 3 (1978), 348–375. issn:0022-0000 https://doi.org/10.1016/0022-0000(78)90014-4
[18]
Lenore Marie Restifo Mullin. 1988. A Mathematics of Arrays. Ph. D. Dissertation. USA. https://dl.acm.org/doi/book/10.5555/915213 AAI8914581
[19]
Amr Sabry and Matthias Felleisen. 1992. Reasoning About Programs in Continuation-passing Style. SIGPLAN Lisp Pointers, V, 1 (1992), Jan., 288–298. issn:1045-3563 https://doi.org/10.1145/141471.141563
[20]
Sven-Bodo Scholz. 1994. Single-assignment C — Functional Programming Using Imperative Style. In 6th International Workshop on Implementation of Functional Languages (IFL’94), Norwich, England, UK, John Glauert (Ed.). University of East Anglia, Norwich, England, UK, 211–2113. https://www.sac-home.org/_media/publications:pdf:sac-overview-norwich-94.pdf
[21]
Justin Slepak, Olin Shivers, and Panagiotis Manolios. 2014. An Array-Oriented Language with Static Rank Polymorphism. In Programming Languages and Systems, Zhong Shao (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 27–46. isbn:978-3-642-54833-8 https://doi.org/10.1007/978-3-642-54833-8_3
[22]
W. W. Tait. 1967. Intensional Interpretations of Functionals of Finite Type I. The Journal of Symbolic Logic, 32, 2 (1967), 198–212. issn:00224812 https://doi.org/10.2307/2271658
[23]
Peter Thiemann and Manuel M. T. Chakravarty. 2013. Agda Meets Accelerate. In Implementation and Application of Functional Languages, Ralf Hinze (Ed.) (IFL ’13). Springer Berlin Heidelberg, Berlin, Heidelberg. 174–189. isbn:978-3-642-41582-1 https://doi.org/10.1007/978-3-642-41582-1_11
[24]
Kai Trojahner and Clemens Grelck. 2009. Dependently typed array programs don’t go wrong. The Journal of Logic and Algebraic Programming, 78, 7 (2009), 643–664. issn:1567-8326 https://doi.org/10.1016/j.jlap.2009.03.002 The 19th Nordic Workshop on Programming Theory (NWPT 2007)
[25]
Niki Vazou, Eric L. Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon Peyton-Jones. 2014. Refinement Types for Haskell. SIGPLAN Not., 49, 9 (2014), aug, 269–282. issn:0362-1340 https://doi.org/10.1145/2692915.2628161
[26]
Hongwei Xi and Frank Pfenning. 1998. Eliminating Array Bound Checking through Dependent Types. In Proceedings of the ACM SIGPLAN 1998 Conference on Programming Language Design and Implementation (PLDI ’98). Association for Computing Machinery, New York, NY, USA. 249–257. isbn:0897919874 https://doi.org/10.1145/277650.277732

Cited By

View all
  • (2024)AUTOMAP: Inferring Rank-Polymorphic Function Applications with Integer Linear ProgrammingProceedings of the ACM on Programming Languages10.1145/36897748:OOPSLA2(1787-1813)Online publication date: 8-Oct-2024

Index Terms

  1. Shape-Constrained Array Programming with Size-Dependent Types
          Index terms have been assigned to the content through auto-classification.

          Recommendations

          Comments

          Information & Contributors

          Information

          Published In

          cover image ACM Conferences
          FHPNC 2023: Proceedings of the 11th ACM SIGPLAN International Workshop on Functional High-Performance and Numerical Computing
          August 2023
          41 pages
          ISBN:9798400702969
          DOI:10.1145/3609024
          Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

          Sponsors

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          Published: 31 August 2023

          Permissions

          Request permissions for this article.

          Check for updates

          Author Tags

          1. functional programming
          2. parallel programming
          3. type systems

          Qualifiers

          • Research-article

          Conference

          FHPNC '23
          Sponsor:

          Acceptance Rates

          Overall Acceptance Rate 18 of 25 submissions, 72%

          Upcoming Conference

          ICFP '25
          ACM SIGPLAN International Conference on Functional Programming
          October 12 - 18, 2025
          Singapore , Singapore

          Contributors

          Other Metrics

          Bibliometrics & Citations

          Bibliometrics

          Article Metrics

          • Downloads (Last 12 months)18
          • Downloads (Last 6 weeks)2
          Reflects downloads up to 20 Jan 2025

          Other Metrics

          Citations

          Cited By

          View all
          • (2024)AUTOMAP: Inferring Rank-Polymorphic Function Applications with Integer Linear ProgrammingProceedings of the ACM on Programming Languages10.1145/36897748:OOPSLA2(1787-1813)Online publication date: 8-Oct-2024

          View Options

          Login options

          View options

          PDF

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader

          Media

          Figures

          Other

          Tables

          Share

          Share

          Share this Publication link

          Share on social media