TY - GEN

T1 - Reflection without remorse

T2 - 2014 6th ACM SIGPLAN Haskell Symposium, Haskell 2014

AU - Ploeg, Atze Van Der

AU - Kiselyov, Oleg

PY - 2014

Y1 - 2014

N2 - A series of list appends or monadic binds for many monads performs algorithmically worse when left-associated. Continuation-passing style (CPS) is well-known to cure this severe dependence of performance on the association pattern. The advantage of CPS dwindles or disappears if we have to examine or modify the intermediate result of a series of appends or binds, before continuing the series. Such examination is frequently needed, for example, to control search in non-determinism monads. We present an alternative approach that is just as general as CPS but more robust: it makes series of binds and other such operations efficient regardless of the association pattern - and also provides efficient access to intermediate results. The key is to represent such a conceptual sequence as an efficient sequence data structure. Efficient sequence data structures from the literature are homogeneous and cannot be applied as they are in a type-safe way to series of monadic binds. We generalize them to type aligned sequences and show how to construct their (assuredly order-preserving) implementations. We demonstrate that our solution solves previously undocumented, severe performance problems in iteratees, LogicT transformers, free monads and extensible effects.

AB - A series of list appends or monadic binds for many monads performs algorithmically worse when left-associated. Continuation-passing style (CPS) is well-known to cure this severe dependence of performance on the association pattern. The advantage of CPS dwindles or disappears if we have to examine or modify the intermediate result of a series of appends or binds, before continuing the series. Such examination is frequently needed, for example, to control search in non-determinism monads. We present an alternative approach that is just as general as CPS but more robust: it makes series of binds and other such operations efficient regardless of the association pattern - and also provides efficient access to intermediate results. The key is to represent such a conceptual sequence as an efficient sequence data structure. Efficient sequence data structures from the literature are homogeneous and cannot be applied as they are in a type-safe way to series of monadic binds. We generalize them to type aligned sequences and show how to construct their (assuredly order-preserving) implementations. We demonstrate that our solution solves previously undocumented, severe performance problems in iteratees, LogicT transformers, free monads and extensible effects.

KW - data structures

KW - monads

KW - performance

KW - reflection

UR - http://www.scopus.com/inward/record.url?scp=84907407794&partnerID=8YFLogxK

UR - http://www.scopus.com/inward/citedby.url?scp=84907407794&partnerID=8YFLogxK

U2 - 10.1145/2633357.2633360

DO - 10.1145/2633357.2633360

M3 - Conference contribution

AN - SCOPUS:84907407794

SN - 9781450330411

T3 - Haskell 2014 - Proceedings of the 2014 ACM SIGPLAN Haskell Symposium

SP - 133

EP - 144

BT - Haskell 2014 - Proceedings of the 2014 ACM SIGPLAN Haskell Symposium

PB - Association for Computing Machinery

Y2 - 4 September 2014 through 5 September 2014

ER -