Hostname: page-component-586b7cd67f-t7czq Total loading time: 0 Render date: 2024-11-28T14:24:59.939Z Has data issue: false hasContentIssue false

Efficient algebraic effect handlers for Prolog

Published online by Cambridge University Press:  14 October 2016

AMR HANY SALEH
Affiliation:
KU Leuven, Belgium, Department of Computer Science (e-mail: [email protected], [email protected])
TOM SCHRIJVERS
Affiliation:
KU Leuven, Belgium, Department of Computer Science (e-mail: [email protected], [email protected])

Abstract

Recent work has provided delimited control for Prolog to dynamically manipulate the program control-flow, and to implement a wide range of control-flow and dataflow effects on top of. Unfortunately, delimited control is a rather primitive language feature that is not easy to use.

As a remedy, this work introduces algebraic effect handlers for Prolog, as a high-level and structured way of defining new side-effects in a modular fashion. We illustrate the expressive power of the feature and provide an implementation by means of elaboration into the delimited control primitives.

The latter add a non-negligible performance overhead when used extensively. To address this issue, we present an optimised compilation approach that combines partial evaluation with dedicated rewrite rules. The rewrite rules are driven by a lightweight effect inference that analyses what effect operations may be called by a goal. We illustrate the effectiveness of this approach on a range of benchmarks.

Type
Regular Papers
Copyright
Copyright © Cambridge University Press 2016 

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

References

Bauer, A. and Pretnar, M. 2015. Programming with algebraic effects and handlers. Journal of Logical and Algebraic Methods in Programming 84, 1, 108123.CrossRefGoogle Scholar
Danvy, O. and Filinski, A. 1990. Abstracting control. LFP '90. 151–160.CrossRefGoogle Scholar
Desouter, B., van Dooren, M. and Schrijvers, T. 2015. Tabling as a library with delimited control. Theory and Practice of Logic Programming 15, 4–5, 419433.CrossRefGoogle Scholar
Dijkstra, E. W. 1968. Letters to the editor: Go to statement considered harmful. Commun. ACM 11, 3 (Mar.), 147148.CrossRefGoogle Scholar
Dolan, S., White, L., Sivaramakrishnan, K., Yallop, J. and Madhavapeddy, A. 2015. Effective concurrency through algebraic effects. In OCaml Users and Developers Workshop.Google Scholar
Felleisen, M. 1988. The theory and practice of first-class prompts. POPL '88. 180–190.CrossRefGoogle Scholar
Holzbaur, C. 1992. Meta-structures vs. Attributed Variables in the context of extensible unification. In Proceedings of the 4th International Symposium on Programming Language Implementation and Logic Programming, LNCS, vol. 631. 260–268.Google Scholar
Ivanovic, D., Morales Caballero, J. F., Carro, M. and Hermenegildo, M. 2009. Towards structured state threading in Prolog. In CICLOPS 2009.Google Scholar
Kammar, O., Lindley, S. and Oury, N. 2013. Handlers in action. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional programming. ICFP '14. ACM, 145158.CrossRefGoogle Scholar
Kiselyov, O., Sabry, A. and Swords, C. 2013. Extensible effects: An alternative to monad transformers. In Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell. Haskell '13. ACM, New York, NY, USA, 5970.CrossRefGoogle Scholar
Plotkin, G. D. and Matija, P. 2013. Handling algebraic effects. Logical Methods in Computer Science 9, 4.Google Scholar
Plotkin, G. D. and Power, J. 2002. Notions of computation determine monads. In Foundations of Software Science and Computation Structures, Nielsen, M. and Engberg, U., Eds. LNCS, vol. 2303. Springer, 342356.CrossRefGoogle Scholar
Roy, P. V. 1989. A useful extension to Prolog's definite clause grammar notation. In ACM SIGPLAN Notices, Vol. 24, 11, Nov. 1989, 132–134.Google Scholar
Schimpf, J. 2002. Logical loops. In International Conference on Logic Programming. Springer, 224238.CrossRefGoogle Scholar
Schrijvers, T., Demoen, B., Desouter, B. and Wielemaker, J. 2013. Delimited continuations for Prolog. Theory and Practice of Logic Programming 13, 4–5, 533546.CrossRefGoogle Scholar
Schrijvers, T., Demoen, B., Triska, M. and Desouter, B. 2014. Tor: Modular search with hookable disjunction. Sci. Comput. Program. 84, 101120.CrossRefGoogle Scholar
Schrijvers, T., Wu, N., Desouter, B. and Demoen, B. 2014. Heuristics entwined with handlers combined. In Proceedings of the 16th International Symposium on Principles and Practice of Declarative Programming, PPDP '14. ACM, 259270.CrossRefGoogle Scholar
Wu, N. and Schrijvers, T. 2015. Fusion for free - efficient algebraic effect handlers. In Mathematics of Program Construction, LNCS, vol. 9129. Springer, 302322.CrossRefGoogle Scholar
Supplementary material: PDF

Saleh and Schrijvers supplementary material

Appendix A-C

Download Saleh and Schrijvers supplementary material(PDF)
PDF 189.9 KB