Type Classes in Functional Logic Programming (Author’s version for E-Prints Complutense)

Type classes provide a clean, modular and elegant way of writing overloaded functions. Functional logic programming languages (FLP in short) like Toy or Curry have adopted the Damas-Milner type system, so it seems natural to adopt also type classes in FLP. However, type classes has been barely introduced in FLP. A reason for this lack of success is that the usual translation of type classes using dictionaries presents some problems in FLP like the absence of expected answers due to a bad interaction of dictionaries with the call-time choice semantics for non-determinism adopted in FLP systems. In this paper we present a type-passing translation of type classes based on type-indexed functions and type witnesses that is well-typed with respect to a new liberal type system recently proposed for FLP. We argue the suitability of this translation for FLP because it improves the dictionary-based one in three aspects. First, it obtains programs which run as fast or faster—with an speedup from 1.05 to 2.30 in our experiments. Second, it solves the mentioned problem of missing answers. Finally, the proposed translation generates shorter and simpler programs. (C) ACM, (2011). This is the authors version of the work. It is posted here by permission of ACM for your personal use. Not for redistribution. The definitive version was published in PEPM ’11 Proceedings of the 20th ACM SIGPLAN workshop on Partial evaluation and program manipulation (January 24–25, 2011, Austin, Texas, USA). http://doi.acm.org/10.1145/1929501.1929524.

[1]  Ralf Hinze,et al.  Open data types and open functions , 2006, PPDP '06.

[2]  Satish R. Thatte Semantics of type classes revisited , 1994, LFP '94.

[3]  Simon L. Peyton Jones,et al.  A history of Haskell: being lazy with class , 2007, HOPL.

[4]  Stephen Blott Type Inference and Type Classes , 1989, Functional Programming.

[5]  Mark P. Jones A system of constructor classes: overloading and implicit higher-order polymorphism , 1993, FPCA '93.

[6]  Simon Peyton Jones,et al.  Type classes: an exploration of the design space , 1997 .

[7]  Simon L. Peyton Jones,et al.  Type classes in Haskell , 1994, TOPL.

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

[9]  James Cheney,et al.  First-Class Phantom Types , 2003 .

[10]  Gang Chen,et al.  Guarded recursive datatype constructors , 2003, POPL '03.

[11]  Philip Wadler,et al.  How to make ad-hoc polymorphism less ad hoc , 1989, POPL '89.

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

[13]  Lennart Augustsson,et al.  Implementing Haskell overloading , 1993, FPCA '93.

[14]  Stephen Blott,et al.  Implementing Haskell Type Classes , 1989, Functional Programming.

[15]  Tobias Nipkow,et al.  Type Reconstruction for Type Classes , 1993 .

[16]  Ralf Hinze,et al.  Generic Programming, Now! , 2006, SSDGP.

[17]  Francisco Javier López-Fraguas,et al.  An Approach to Declarative Programming Based on a Rewriting Logic , 1999, J. Log. Program..

[18]  Rita Loogen,et al.  A Demand Driven Computation Strategy for Lazy Narrowing , 1993, PLILP.

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

[20]  Alexander A. Stepanov,et al.  Generic Programming , 1988, ISSAC.