Polytypic Functional Programming

نویسنده

  • Pablo Nogueira Iglesias
چکیده

Structural polymorphism is a generic programming technique known within the functional programming community under the names of polytypic or datatype-generic programming. In this thesis we show that such a technique conflicts with the principle of data abstraction and propose a solution for reconciliation. More concretely, we show that popular polytypic extensions of the functional programming language Haskell, namely, Generic Haskell and Scrap your Boilerplate have their genericity limited by data abstraction. We propose an extension to the Generic Haskell language where the ‘structure’ in ‘structural polymorphism’ is defined around the concept of interface and not the representation of a type. More precisely, polytypic functions capture families of polymorphic functions in one single template definition. Instances of a polytypic function for specific algebraic types can be generated automatically by a compiler following the definitional structure of the types. However, the definitional structure of an abstract type is, for maintainability reasons, logically hidden and, sometimes, even physically unavailable (e.g., precompiled libraries). Even if the representation is known, the semantic gap between an abstract type and its representation type makes automatic generation difficult, if not impossible. Furthermore, if it were possible it would nevertheless be impractical: the code generated from the definitional structure of the internal representation is rendered obsolete when the representation changes. The purpose of an abstract type is to minimise the impact of representation changes on client code. Data abstraction is upheld by client code, whether polytypic or not, when it works with abstract types through their public interfaces. Fortunately, interfaces can provide enough description of ‘structure’ to guide the automatic construction of two polytypic functions that extract and insert data from abstract types to concrete types and vice versa. Polytypic functions can be defined in this setting in terms of polytypic insertion, polytypic extraction, and ordinary polytypic functions on concrete types. We propose the extension of the Generic Haskell language with mechanisms that enable programmers to supply the necessary information. The scheme relies on another proposed extension to support polytypic programming with type-class constrained types, which we show are not supported by Generic Haskell.

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Polytypic Programming With Ease

A functional polytypic program is one that is parameterised by datatype. Since poly-typic functions are deened by induction on types rather than by induction on values they typically operate on a higher level of abstraction than their monotypic counterparts. However, polytypic programming is not necessarily more complicated than conventional programming. We show that a polytypic function is uni...

متن کامل

Polytypic Syntax Tree Operations

Polytypic functional programming has the advantage that it can derive code for generic functions automatically. However, it is not clear whether it is useful for anything other than the textbook examples, and the generated polytypic code is usually too slow for real-life programs. As a real-life test, we derive a polytypic parser for the Haskell 98 syntax and look into other front-end compiler ...

متن کامل

Polytypic Functions Over Nested Datatypes

The theory and practice of polytypic programming is intimately connected with the initial algebra semantics of datatypes. This is both a blessing and a curse. It is a blessing because the underlying theory is beautiful and well developed. It is a curse because the initial algebra semantics is restricted to so-called regular datatypes. Recent work by R. Bird and L. Meertens [3] on the semantics ...

متن کامل

Polytypic Programming in Haskell

A polytypic (or generic) program captures a common pattern of computation over di erent datatypes by abstracting over the structure of the datatype. Examples of algorithms that can be de ned polytypically are equality tests, mapping functions and pretty printers. A commonly used technique to implement polytypic programming is specialization, where a specialized version of a polytypic function i...

متن کامل

Polytypic Programming

Many functions have to be written over and over again for different datatypes, either because datatypes change during the development of programs, or because functions with similar functionality are needed on diierent datatypes. Examples of such functions are pretty printers, debug-gers, equality functions, uniiers, pattern matchers, rewriting functions, etc. Such functions are called polytypic...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2006