Typing as functional-logic evaluation

We present a transformational approach to type inference for functional logic programs. More concretely, we give a broad set of examples showing how, given a functional logic program P, we can synthesize a remarkably simple and natural functional logic program P' such that the evaluation of expressions with respect to P' corresponds to typing the expressions in the original P. We start developing those ideas for the case of type inference with standard Hindley-Milner types, and after that we consider some variations, like local definitions with different degrees of polymorphism, existential types and type checking in the presence of polymorphic recursion. For the basic case of Hindley-Milner types we provide also a formalization of the transformation and proofs of its correctness. Besides its potential applicability to the implementation of different type systems, or to the educational use of the synthesized typing programs to explain different type inference/checking processes, the paper demonstrates vividly the expressive power of functional logic languages, as well as some of their limitations for metaprogramming purposes, that we have overcome by providing a suitable set of metalogical functions to inspect, classify and manipulate expressions according to their structure, similar to well known Prolog metapredicates for such purposes.

[1]  Simon Marlow,et al.  Haskell 2010 Language Report , 2010 .

[2]  Tom Schrijvers,et al.  Polymorphic algebraic data type reconstruction , 2006, PPDP '06.

[3]  Luís Damas Type assignment in programming languages , 1984 .

[4]  Michael Hanus,et al.  Curry: an integrated functional logic language (version 0 , 2003 .

[5]  Lee Naish A Higher Order Rewriting Logic for Functional Logic Programming , 1997 .

[6]  Juan Rodríguez-Hortalá,et al.  Rewriting and Call-Time Choice: The HO Case , 2008, FLOPS.

[7]  John C. Mitchell,et al.  Abstract types have existential types , 1985, POPL.

[8]  Martin Odersky,et al.  Polymorphic type inference and abstract data types , 1994, TOPL.

[9]  Enrique Martin-Martin,et al.  Well-typed narrowing with extra variables in functional-logic programming , 2012, PEPM '12.

[10]  J. C. Gonz Alez-Moreno,et al.  An Approach to Declarative Programming Based on a Rewriting Logic , 2022 .

[11]  Peter J. Stuckey,et al.  Under Consideration for Publication in J. Functional Programming Hm(x) Type Inference Is Clp(x) Solving , 2022 .

[12]  Sergio Antoy Definitional Trees , 1992, ALP.

[13]  Rafael del Vado Vírseda,et al.  A new generic scheme for functional logic programming with constraints , 2007, High. Order Symb. Comput..

[14]  G. G. Stokes "J." , 1890, The New Yale Book of Quotations.

[15]  Jean-Christophe Janodet,et al.  Admissible Graph Rewriting and Narrowing , 1998, IJCSLP.

[16]  L FranciscoJ. A new generic scheme for functional logic programming with constraints , 2007 .

[17]  François Pottier,et al.  A Versatile Constraint-Based Type Inference System , 2000, Nord. J. Comput..

[18]  Alan Mycroft,et al.  Polymorphic Type Schemes and Recursive Definitions , 1984, Symposium on Programming.

[19]  Rachid Echahed,et al.  A needed narrowing strategy , 2000, JACM.

[20]  Michael Hanus,et al.  Multi-paradigm Declarative Languages , 2007, ICLP.

[21]  Simon Peyton Jones,et al.  The Implementation of Functional Programming Languages (Prentice-hall International Series in Computer Science) , 1987 .

[22]  Mario Rodríguez-Artalejo,et al.  Polymorphic Types in Functional Logic Programming , 2001, J. Funct. Log. Program..

[23]  Enrique Martin-Martin,et al.  New Results on Type Systems for Functional Logic Programming , 2009, WFLP.

[24]  Michael Hanus,et al.  Functional logic programming , 2010, CACM.

[25]  W. Marsden I and J , 2012 .

[26]  Martin Odersky,et al.  Type Inference with Constrained Types , 1999, Theory Pract. Object Syst..

[27]  Francisco Javier López-Fraguas,et al.  TOY: A Multiparadigm Declarative System , 1999, RTA.

[28]  Michael Hanus,et al.  The Integration of Functions into Logic Programming: From Theory to Practice , 1994, J. Log. Program..

[29]  Simon L. Peyton Jones,et al.  The Implementation of Functional Programming Languages , 1987 .

[30]  Robin Milner,et al.  Principal type-schemes for functional programs , 1982, POPL '82.