Skip to main content

Types, Modes and so Much More – The Prolog Way

  • Chapter
  • First Online:
Prolog: The Next 50 Years

Part of the book series: Lecture Notes in Computer Science ((LNAI,volume 13900))

Abstract

We present in a tutorial way some ideas developed in the context of the Ciao Prolog system that we believe could be useful for the future evolution of Prolog. We concentrate primarily on one area: the use of assertions with types, modes, and other properties, and how the unique characteristics of Prolog have made early advances possible in the area of combining static and dynamic language features. However, we also address briefly some other issues related to extending the expressiveness and functionality of the language.

Partially funded by MICINN projects PID2019-108528RB-C21 ProCode, TED2021-132464B-I00 PRODIGY, and FJC2021-047102-I, by the Comunidad de Madrid program P2018/TCS-4339 BLOQUES-CM, and by the Tezos foundation. The authors would also like to thank the anonymous reviewers for very useful feedback.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 64.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 84.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    The examples are runnable in the Ciao playground ; they have been developed with version 1.22 of the system. Screenshots are from the Ciao Prolog Emacs interface.

  2. 2.

    Due to space limitations we present the assertion language through –hopefully intuitive– examples. More complete descriptions of the assertion language can be found in [2, 12, 29].

  3. 3.

    See, e.g., [43] in this same volume for an introduction to modes.

  4. 4.

    Note that while, as mentioned before, the assertions in Fig. 4 use modes they are represented internally in normal form and the popup message uses syntax close to this form, where the computational properties and the state properties that must hold upon success are split into separate (comp and success assertions respectively).

  5. 5.

    An upper bound [26, 35] is also inferred, equal to the lower bound (Fig. 17).

  6. 6.

    See again [43] for in introduction to term expansion in Prolog.

References

  1. Arias, J., Carro, M., Salazar, E., Marple, K., Gupta, G.: Constraint answer set programming without grounding. Theory Pract. Logic Program. 18(3–4), 337–354 (2018). https://doi.org/10.1017/S1471068418000285

    Article  MathSciNet  MATH  Google Scholar 

  2. Bueno, F., Carro, M., Hermenegildo, M.V., Lopez-Garcia, P., Morales, J. (eds.) The Ciao System. Reference Manual (v1.22). Techncial report, April 2023. https://ciao-lang.org

  3. Bueno, F., et al.: On the role of semantic approximations in validation and diagnosis of constraint logic programs. In: Proceedings of the 3rd International WS on Automated Debugging-AADEBUG, pp. 155–170. U. Linköping Press, May 1997

    Google Scholar 

  4. Bueno, F., López-García, P., Hermenegildo, M.: Multivariant non-failure analysis via standard abstract interpretation. In: Kameyama, Y., Stuckey, P.J. (eds.) FLOPS 2004. LNCS, vol. 2998, pp. 100–116. Springer, Heidelberg (2004). https://doi.org/10.1007/978-3-540-24754-8_9

    Chapter  Google Scholar 

  5. Cabeza, D., Hermenegildo, M.: A new module system for prolog. In: Lloyd, J., et al. (eds.) CL 2000. LNCS (LNAI), vol. 1861, pp. 131–148. Springer, Heidelberg (2000). https://doi.org/10.1007/3-540-44957-4_9

    Chapter  Google Scholar 

  6. Carro, M., Morales, J., Muller, H., Puebla, G., Hermenegildo, M.V.: High-level languages for small devices: a case study. In: Flautner, K., Kim, T. (eds.) Compilers, Architecture, and Synthesis for Embedded Systems, pp. 271–281. ACM Press / Sheridan, October 2006

    Google Scholar 

  7. Cousot, P., Cousot, R.: Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In: ACM Symposium on Principles of Programming Languages (POPL’77), pp. 238–252. ACM Press (1977). https://doi.org/10.1145/512950.512973

  8. Debray, S.K., Lopez-Garcia, P., Hermenegildo, M.V., Lin, N.W.: Lower bound cost estimation for logic programs. In: ILPS’97, pp. 291–305. MIT Press (1997)

    Google Scholar 

  9. Debray, S., Lopez-Garcia, P., Hermenegildo, M.V.: Non-failure analysis for logic programs. In: ICLP’97, pp. 48–62. MIT Press (1997)

    Google Scholar 

  10. Giacobazzi, R., Ranzato, F.: History of abstract interpretation. IEEE Ann. Hist. Comput. 44(2), 33–43 (2022). https://doi.org/10.1109/MAHC.2021.3133136

  11. Gupta, G., Salazar, E., Arias, J., Basu, K., Varanasi, S., Carro, M.: Prolog: past, present, and future. In: Warren, D.S., Dahl, V., Eiter, T., Hermenegildo, M., Kowalski, R., Rossi, F. (eds.) Prolog: The Next 50 Years. LNCS (LNAI), vol. 13900, pp. 48–61. Springer, Cham (2023). https://doi.org/10.1007/978-3-031-35254-6_4

  12. Hermenegildo, M.V., et al.: An overview of ciao and its design philosophy. Theory Pract. Logic Program. 12(1–2), 219–252 (2012)

    Google Scholar 

  13. Hermenegildo, M.V., Puebla, G., Bueno, F.: Using global analysis, partial specifications, and an extensible assertion language for program validation and debugging. In: Apt, K.R., Marek, V.W., Truszczynski, M., Warren, D.S. (eds.) The Logic Programming Paradigm: a 25-Year Perspective, pp. 161–192. Springer, Heidelberg (1999). https://doi.org/10.1007/978-3-642-60085-2_7

  14. Hermenegildo, M.V., Puebla, G., Bueno, F., Lopez-Garcia, P.: Integrated program debugging, verification, and optimization using abstract interpretation (and the Ciao system preprocessor). Sci. Comput. Program. 58(1–2), 115–140 (2005). https://doi.org/10.1016/j.scico.2005.02.006

    Article  MathSciNet  MATH  Google Scholar 

  15. Hermenegildo, M., Morales, J., Lopez-Garcia, P.: Some thoughts on how to teach prolog. In: Warren, D.S., Dahl, V., Eiter, T., Hermenegildo, M., Kowalski, R., Rossi, F. (eds.) Prolog: The Next 50 Years. LNCS (LNAI), vol. 13900, pp. 107–123. Springer, Cham (2023). https://doi.org/10.1007/978-3-031-35254-6_9

  16. Holzbaur, C.: Metastructures vs. attributed variables in the context of extensible unification. In: Bruynooghe, M., Wirsing, M. (eds.) PLILP 1992. LNCS, vol. 631, pp. 260–268. Springer, Heidelberg (1992). https://doi.org/10.1007/3-540-55844-6_141

    Chapter  Google Scholar 

  17. Hudak, P., et al.: Report on the programming language Haskell. Haskell Spec. Issue, ACM SIGPLAN Not. 27(5), 1–164 (1992)

    Google Scholar 

  18. Logozzo, F., et al.: Clousot. https://msdn.microsoft.com/en-us/devlabs/dd491992.aspx. Accessed 2018

  19. Lopez-Garcia, P., Bueno, F., Hermenegildo, M.V.: Automatic inference of determinacy and mutual exclusion for logic programs using mode and type analyses. N. Gener. Comput. 28(2), 117–206 (2010)

    MATH  Google Scholar 

  20. Lopez-Garcia, P., Klemen, M., Liqat, U., Hermenegildo, M.V.: A general framework for static profiling of parametric resource usage. TPLP (ICLP’16 Spec. Issue) 16(5–6), 849–865 (2016). https://doi.org/10.1017/S1471068416000442

  21. Mera, E., Lopez-García, P., Hermenegildo, M.: Integrating software testing and run-time checking in an assertion verification framework. In: Hill, P.M., Warren, D.S. (eds.) ICLP 2009. LNCS, vol. 5649, pp. 281–295. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-02846-5_25

    Chapter  Google Scholar 

  22. Morales, J., Carro, M., Hermenegildo, M.V.: Description and optimization of abstract machines in a dialect of prolog. Theory Pract. Logic Program. 16(1), 1–58 (2016). https://doi.org/10.1017/S1471068414000672

    Article  MathSciNet  MATH  Google Scholar 

  23. MSR: Code contracts. https://research.microsoft.com/en-us/projects/contracts/. Accessed 2018

  24. Muthukumar, K., Hermenegildo, M.: Combined determination of sharing and freeness of program variables through abstract interpretation. In: ICLP’91, pp. 49–63. MIT Press, June 1991

    Google Scholar 

  25. Muthukumar, K., Hermenegildo, M.: Compile-time derivation of variable dependency using abstract interpretation. JLP 13(2/3), 315–347 (1992)

    Article  MATH  Google Scholar 

  26. Navas, J., Mera, E., López-García, P., Hermenegildo, M.V.: User-definable resource bounds analysis for logic programs. In: Dahl, V., Niemelä, I. (eds.) ICLP 2007. LNCS, vol. 4670, pp. 348–363. Springer, Heidelberg (2007). https://doi.org/10.1007/978-3-540-74610-2_24

    Chapter  Google Scholar 

  27. Nguyen, P.C., Tobin-Hochstadt, S., Van Horn, D.: Soft contract verification. In: Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming. ICFP ’14, pp. 139–152. ACM, New York, NY, USA (2014). https://doi.org/10.1145/2628136.2628156

  28. Pfenning, F.: Dependent types in logic programming. In: Pfenning, F. (ed.) Types in Logic Programming, pp. 285–311. The MIT Press (1992)

    Google Scholar 

  29. Puebla, G., Bueno, F., Hermenegildo, M.: An assertion language for constraint logic programs. In: Deransart, P., Hermenegildo, M.V., Małuszynski, J. (eds.) Analysis and Visualization Tools for Constraint Programming. LNCS, vol. 1870, pp. 23–61. Springer, Heidelberg (2000). https://doi.org/10.1007/10722311_2

    Chapter  Google Scholar 

  30. Puebla, G., Bueno, F., Hermenegildo, M.: Combined static and dynamic assertion-based debugging of constraint logic programs. In: Bossi, A. (ed.) LOPSTR 1999. LNCS, vol. 1817, pp. 273–292. Springer, Heidelberg (2000). https://doi.org/10.1007/10720327_16

    Chapter  MATH  Google Scholar 

  31. Rastogi, A., Swamy, N., Fournet, C., Bierman, G., Vekris, P.: Safe & efficient gradual typing for typescript. In: 42nd POPL, pp. 167–180. ACM, January 2015

    Google Scholar 

  32. Rondon, P.M., Kawaguchi, M., Jhala, R.: Liquid types. In: Gupta, R., Amarasinghe, S.P. (eds.) Proceedings of the ACM SIGPLAN 2008 Conference on Programming Language Design and Implementation, Tucson, AZ, USA, 7–13 June 2008, pp. 159–169. ACM (2008). https://doi.org/10.1145/1375581.1375602

  33. Saglam, H., Gallagher, J.: Approximating constraint logic programs using polymorphic types and regular descriptions. Technical report CSTR-95-17, Department of Computer Science, U. of Bristol, Bristol BS8 1TR (1995)

    Google Scholar 

  34. Sanchez-Ordaz, M., Garcia-Contreras, I., Perez-Carrasco, V., Morales, J.F., Lopez-Garcia, P., Hermenegildo, M.V.: Verifly: on-the-fly assertion checking via incrementality. Theory Pract. Logic Program. 21(6), 768–784 (2021)

    Google Scholar 

  35. Serrano, A., Lopez-Garcia, P., Hermenegildo, M.V.: Resource usage analysis of logic programs via abstract interpretation using sized types. TPLP, ICLP’14 Spec. Issue 14(4–5), 739–754 (2014). https://doi.org/10.1017/S147106841400057X

  36. Siek, J.G., Taha, W.: Gradual typing for functional languages. In: Scheme and Functional Programming Workshop, pp. 81–92 (2006)

    Google Scholar 

  37. Somogyi, Z., Henderson, F., Conway, T.: The execution algorithm of mercury: an efficient purely declarative logic programming language. JLP 29(1–3), 17–64 (1996)

    Article  MATH  Google Scholar 

  38. Swift, T., Warren, D.S.: XSB: extending prolog with tabled logic programming. Theory Pract. Logic Program. 12(1–2), 157–187 (2012). https://doi.org/10.1017/S1471068411000500

    Article  MathSciNet  MATH  Google Scholar 

  39. Takikawa, A., et al.: Towards practical gradual typing. In: Boyland, J.T. (ed.) 29th European Conference on Object-Oriented Programming, ECOOP 2015, 5–10 July 2015, Prague, Czech Republic. LIPIcs, vol. 37, pp. 4–27. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik (2015). https://doi.org/10.4230/LIPIcs.ECOOP.2015.4

  40. Tobin-Hochstadt, S., Felleisen, M.: The design and implementation of typed scheme. In: POPL, pp. 395–406. ACM (2008)

    Google Scholar 

  41. Vaucheret, C., Bueno, F.: More precise yet efficient type inference for logic programs. In: Hermenegildo, M.V., Puebla, G. (eds.) SAS 2002. LNCS, vol. 2477, pp. 102–116. Springer, Heidelberg (2002). https://doi.org/10.1007/3-540-45789-5_10

    Chapter  Google Scholar 

  42. Vazou, N., Tanter, É., Horn, D.V.: Gradual liquid type inference. Proc. ACM Program. Lang. 2(OOPSLA), 132:1–132:25 (2018). https://doi.org/10.1145/3276502

  43. Warren, D.S.: Introduction to prolog. In: Warren, D.S., Dahl, V., Eiter, T., Hermenegildo, M., Kowalski, R., Rossi, F. (eds.) Prolog: The Next 50 Years. LNCS (LNAI), vol. 13900, pp. 3–19. Springer, Cham (2023). https://doi.org/10.1007/978-3-031-35254-6_1

  44. Xi, H., Pfenning, F.: Dependent types in practical programming. In: Appel, A.W., Aiken, A. (eds.) POPL ’99, Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Antonio, TX, USA, 20–22 January 1999. pp. 214–227. ACM (1999). https://doi.org/10.1145/292540.292560

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Manuel V. Hermenegildo .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2023 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Hermenegildo, M.V., Morales, J.F., Lopez-Garcia, P., Carro, M. (2023). Types, Modes and so Much More – The Prolog Way. In: Warren, D.S., Dahl, V., Eiter, T., Hermenegildo, M.V., Kowalski, R., Rossi, F. (eds) Prolog: The Next 50 Years. Lecture Notes in Computer Science(), vol 13900. Springer, Cham. https://doi.org/10.1007/978-3-031-35254-6_2

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-35254-6_2

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-35253-9

  • Online ISBN: 978-3-031-35254-6

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics