APLicative Programming with Naperian Functors

Much of the expressive power of array-oriented languages such as Iverson’s APL and J comes from their implicit lifting of scalar operations to act on higher-ranked data, for example to add a value to each element of a vector, or to add two compatible matrices pointwise. It is considered a shape error to attempt to combine arguments of incompatible shape, such as a 3-vector with a 4-vector. APL and J are dynamically typed, so such shape errors are caught only at run-time. Recent work by Slepak et al. develops a custom type system for an array-oriented language, statically ruling out such errors. We show here that such a custom language design is unnecessary: the requisite compatibility checks can already be captured in modern expressive type systems, as found for example in Haskell; moreover, generative type-driven programming can exploit that static type information constructively to automatically induce the appropriate liftings. We show also that the structure of multi-dimensional data is inherently a matter of Naperian applicative functors—lax monoidal functors, with strength, commutative up to isomorphism under composition—that also support traversal.

[1]  Conor McBride Faking it: Simulating dependent types in Haskell , 2002, J. Funct. Program..

[2]  Frederik Eaton,et al.  Statically typed linear algebra in Haskell , 2006, Haskell '06.

[3]  Richard S. Bird,et al.  Nested Datatypes , 1998, MPC.

[4]  Conor McBride,et al.  Hasochism: the pleasure and pain of dependently typed haskell programming , 2013, Haskell '13.

[5]  James McKinna,et al.  Why dependent types matter , 2006, POPL '06.

[6]  Alan Mycroft,et al.  Polymorphic Type Schemes and Recursive Definitions , 1984, Symposium on Programming.

[7]  Matthias Felleisen,et al.  Semantics Engineering with PLT Redex , 2009 .

[8]  Simon L. Peyton Jones,et al.  Regular, shape-polymorphic, parallel arrays in Haskell , 2010, ICFP '10.

[9]  Ralf Hinze,et al.  Manufacturing datatypes , 2001, J. Funct. Program..

[10]  Martin Elsman,et al.  Compiling a Subset of APL Into a Typed Intermediate Language , 2014, ARRAY@PLDI.

[11]  Todd L. Veldhuizen,et al.  Arrays in Blitz++ , 1998, ISCOPE.

[12]  Ralf Hinze,et al.  Fun with phantom types , 2003 .

[13]  Clemens Grelck,et al.  Dependently typed array programs don't go wrong , 2009, J. Log. Algebraic Methods Program..

[14]  Bo Joel Svensson,et al.  Expressive array constructs in an embedded GPU kernel programming language , 2012, DAMP '12.

[15]  Panagiotis Manolios,et al.  An Array-Oriented Language with Static Rank Polymorphism , 2014, ESOP.

[16]  Chris Okasaki,et al.  Purely functional data structures , 1998 .

[17]  Simon L. Peyton Jones,et al.  Unboxed Values as First Class Citizens in a Non-Strict Functional Language , 1991, FPCA.

[18]  Mary Sheeran,et al.  The Design and Implementation of Feldspar - An Embedded Language for Digital Signal Processing , 2010, IFL.

[19]  Frank Pfenning,et al.  Eliminating array bound checking through dependent types , 1998, PLDI.

[20]  Jon Louis Bentley,et al.  Quad trees a data structure for retrieval on composite keys , 1974, Acta Informatica.

[21]  Manuel M. T. Chakravarty,et al.  Agda Meets Accelerate , 2012, IFL.

[22]  Kenneth E. Iverson,et al.  A programming language , 1899, AIEE-IRE '62 (Spring).

[23]  Tom Schrijvers,et al.  Understanding idiomatic traversals backwards and forwards , 2013, Haskell '13.

[24]  Oege de Moor,et al.  The Fun of Programming , 2003 .

[25]  J. Robin B. Cockett,et al.  Shapely Types and Shape Polymorphism , 1994, ESOP.

[26]  Akinori Abe,et al.  A Simple and Practical Linear Algebra Library Interface with Static Size Checking , 2015, ML/OCaml.

[27]  Sven-Bodo Scholz,et al.  Functional Array Programming in SaC , 2005, CEFP.

[28]  Patrik Jansson,et al.  An agda formalisation of the transitive closure of block matrices (extended abstract) , 2016, TyDe@ICFP.

[29]  Leonidas J. Guibas,et al.  Compilation and delayed evaluation in APL , 1978, POPL.

[30]  Simon L. Peyton Jones,et al.  Giving Haskell a promotion , 2012, TLDI '12.

[31]  Manuel M. T. Chakravarty,et al.  Accelerating Haskell array codes with multicore GPUs , 2011, DAMP '11.

[32]  Jurriaan Hage,et al.  Type families with class, type classes with family , 2015, Haskell.

[33]  Paul Hudak,et al.  Functional reactive animation , 1997, ICFP '97.

[34]  Conor McBride,et al.  Applicative programming with effects , 2008, J. Funct. Program..