Fixing idioms

Dominique Devriese, Ilya Sergey, Dave Clarke, Frank Piessens
2013 Proceedings of the ACM SIGPLAN 2013 workshop on Partial evaluation and program manipulation - PEPM '13  
In a lazy functional language, the standard encoding of recursion in DSLs uses the host language's recursion, so that DSL algorithms automatically use the host language's least fixpoints, even though many domains require algorithms to produce different fixpoints. In particular, this is the case for DSLs implemented as Applicative functors (structures with a notion of pure computations and function application). We propose a recursion primitive afix that models a recursive binder in a finally
more » ... less HOAS encoding, but with a novel rank-2 type that allows us to specify and exploit the effectsvalues separation that characterises Applicative DSLs. Unlike related approaches for Monad s and Arrow s, we model effectful recursion, not value recursion. Using generic programming techniques, we define an aritygeneric version of the operator to model mutually recursive definitions. We recover intuitive user syntax with a form of shallow syntactic sugar: an alet construct that syntactically resembles the let construct, which we have implemented in the GHC Haskell compiler. We describe a proposed axiom for the afix operator. We demonstrate usefulness with examples from Applicative parser combinators and functional reactive programming. We show how higher-order recursive operators like many can be encoded without special library support, unlike previous approaches, and we demonstrate an implementation of the left recursion removal transform.
doi:10.1145/2426890.2426910 dblp:conf/pepm/DevrieseSCP13 fatcat:4mjxt5sn2vazzjgb27wjboecfi