An Ode to Arrows

We study a number of embedded DSLs for autonomous ordinary differential equations (autonomous ODEs) in Haskell. A naive implementation based on the lazy tower of derivatives is straightforward but has serious time and space leaks due to the loss of sharing when handling cyclic and infinite data structures. In seeking a solution to fix this problem, we explore a number of DSLs ranging from shallow to deep embeddings, and middle-grounds in between. We advocate a solution based on arrows, an abstract notion of computation that offers both a succinct representation and an effective implementation. Arrows are ubiquitous in their combinator style that happens to capture both sharing and recursion elegantly. We further relate our arrow-based DSL to a more constrained form of arrows called causal commutative arrows, the normalization of which leads to a staged compilation technique improving ODE performance by orders of magnitude.

[1]  Tim Sheard,et al.  Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space) , 1996, POPL '96.

[2]  Jerzy Karczmarczuk,et al.  Functional Differentiation of Computer Programs , 1998, ICFP '98.

[3]  John Hughes,et al.  Generalising monads to arrows , 2000, Sci. Comput. Program..

[4]  Koen Claessen,et al.  Observable Sharing for Functional Circuit Description , 1999, ASIAN.

[5]  Mary Sheeran,et al.  Lava: hardware design in Haskell , 1998, ICFP '98.

[6]  D. A. Turner,et al.  A new implementation technique for applicative languages , 1979, Softw. Pract. Exp..

[7]  P. S. Thiagarajan,et al.  Advances in Computing Science — ASIAN’99 , 1999, Lecture Notes in Computer Science.

[8]  Richard S. Bird,et al.  de Bruijn notation as a nested datatype , 1999, Journal of Functional Programming.

[9]  Andy Gill,et al.  Type-safe observable sharing in Haskell , 2009, Haskell.

[10]  Conal Elliott Beautiful differentiation , 2009, ICFP.

[11]  John T. O'Donnell,et al.  Generating Netlists from Executable Circuit Specifications , 1992, Functional Programming.

[12]  Henrik Nilsson,et al.  Functional reactive programming, continued , 2002, Haskell '02.

[13]  Paul Hudak,et al.  Causal commutative arrows and their optimization , 2009, ICFP.

[14]  DONALD MICHIE,et al.  “Memo” Functions and Machine Learning , 1968, Nature.

[15]  Neil Ghani,et al.  Representing Cyclic Structures as Nested Datatypes , 2006 .

[16]  Paul Hudak,et al.  Plugging a Space Leak with an Arrow , 2007, Festschrift honoring Gary Lindstrom.

[17]  Ross Paterson,et al.  A new notation for arrows , 2001, ICFP '01.

[18]  Antony Courtney,et al.  Genuinely Functional User Interfaces , 2001 .