- Research Article
- 10.1016/j.entcs.2004.11.021
Programmable Rewriting Strategies in Haskell: — White Paper —
- Apr 01, 2005
- Electronic Notes in Theoretical Computer Science
- Ralf Lämmel
Programmable Rewriting Strategies in Haskell: — White Paper —
Abstract A generic functional program is one which is parameterised by datatype. By installing specific choices, for example lists or trees, different programs are obtained that are, nevertheless, abstractly the same. The purpose of this paper is to explore the possibility of deriving generic programs. Part of the theory of lists that deals with segments is recast as a theory about ‘segments’ in a wide class of datatypes, and then used to pose and solve a generic version of a well-known problem.
Programmable Rewriting Strategies in Haskell: — White Paper —
Programmable Rewriting Strategies in Haskell: — White Paper —
Scrap your boilerplate with XPath-like combinators
XML programming involves idioms for expressing 'structure shyness' such as the descendant axis of XPath or the default templates of XSLT. We initiate a discussion of the relationships between such XML idioms and generic functional programming, while focusing on the (Haskell-based) 'Scrap your boilerplate' style of generic programming (SYB). This work gives insight into mechanisms for traversal and selection. We compare SYB and XSLT. We approximate XPath in SYB. We make a case for SYB's programmability, when compared to XPath's fixed combinators. We allude to strengthened type checking for SYB traversals so as to reject certain, trivial behaviors.
Read moreFully Generic Programming Over Closed Universes of Inductive-Recursive Types
Dependently typed programming languages allow the type system to express arbitrary propositions of intuitionistic logic, thanks to the Curry-Howard isomorphism. Taking full advantage of this type system requires defining more types than usual, in order to encode logical correctness criteria into the definitions of datatypes. While an abundance of specialized types helps ensure correctness, it comes at the cost of needing to redefine common functions for each specialized type. This dissertation makes an effort to attack the problem of code reuse in dependently typed languages. Our solution is to write generic functions, which can be applied to any datatype. Such a generic function can be applied to datatypes that are defined at the time the generic function was written, but they can also be applied to any datatype that is defined in the future. Our solution builds upon previous work on generic programming within dependently typed programming. Type theory supports generic programming using a construction known as a universe. A universe can be considered the model of a programming language, such that writing functions over it models writing generic programs in the programming language. Historically, there has been a trade-off between the expressive power of the modeled programming language, and the kinds of generic functions that can be written in it. Our dissertation shows that no such trade-off is necessary, and that we can write future-proof generic functions in a model of a dependently typed programming language with a rich collection of types.
Read moreSpecial Issue on Generic Programming Editorial
Generic programming is about making programs more adaptable by making them more general. Generic programs often embody non-traditional kinds of polymorphism; ordinary programs are obtained from them by suitably instantiating their parameters. In contrast to normal programs, the parameters of a generic program are often quite rich in structure; for example, they may be other programs, types or type constructors, classes, concepts, or even programming paradigms.
Read moreComparing libraries for generic programming in haskell
Datatype-generic programming is defining functions that depend on the structure, or shape, of datatypes. It has been around for more than 10 years, and a lot of progress has been made, in particular in the lazy functional programming language Haskell. There are morethan 10 proposals for generic programming libraries orlanguage extensions for Haskell. To compare and characterise the many generic programming libraries in atyped functional language, we introduce a set of criteria and develop a generic programming benchmark: a set of characteristic examples testing various facets of datatype-generic programming. We have implemented the benchmark for nine existing Haskell generic programming libraries and present the evaluation of the libraries. The comparison is useful for reaching a common standard for generic programming, but also for a programmer who has to choose a particular approach for datatype-generic programming.
Read moreGeneric programming with combinators and objects
The generic programming approach is popular in functional languages (for example, OCaml, Haskell). In essence, it is a compile-time generation of code that performs transformations of user-defined data types. The generated code can carry out various kinds of transformations of the values. Usually, transformations are represented as functions that implement algorithms of transformation. New transformations could be built from these transformation functions and user-defined ones. The representation based on functions has a downside: functions behave as final representations, and hence it is not possible to modify the behavior of the already built function. If the current set of transformations does not suit well, software developers are obliged to write a completely distinct transformation, even in the case when the new transformation is almost identical to the existing one. This work proposes to build transformations that are extensible after construction. The object-oriented programming paradigm will be followed, transformations will be represented not as functions but as objects. Instead of calling a transformation function, one of the object’s methods will be called. The transformation itself will be split into methods. The extensibility is supported by adding new methods and overriding existing ones. In this paper, the authors propose an approach to represent transformations as objects in the OCaml functional programming language. Every alternative in data type definition has a corresponding object method. This design allows the construction of many distinct transformations. The cases where too many methods are not desirable are also discussed. The method is applicable to represent extensible transformations for polymorphic variant data types in OCaml when other methods fail to do it. The method is not bound to any particular domain. It allows the creation of extensible transformations in OCaml. It could be ported to other functional languages supporting object-oriented programming.
Read moreAlgebraic Data Types
Algebraic data types are the natural target of pattern-matching functions. When the type is parametric then the pattern-matching functions typically support parametric polymorphism. In addition, bondi supports generic functional programming by introducing a small family of primitive, or representing data types, which can be used to define generic functions such as map, with one case for each primitive constructor. Each resulting case has a different type, so type specialisation is involved, too. During a type declaration, additional cases can be added to existing functions.
Read moreType-Safe Two-Level Data Transformation
A two-level data transformation consists of a type-level transformation of a data format coupled with value-level transformations of data instances corresponding to that format. Examples of two-level data transformations include XML schema evolution coupled with document migration, and data mappings used for interoperability and persistence. We provide a formal treatment of two-level data transformations that is type-safe in the sense that the well-formedness of the value-level transformations with respect to the type-level transformation is guarded by a strong type system. We rely on various techniques for generic functional programming to implement the formalization in Haskell. The formalization addresses various two-level transformation scenarios, covering fully automated as well as user-driven transformations, and allowing transformations that are information-preserving or not. In each case, two-level transformations are disciplined by one-step transformation rules and type-level transformations induce value-level transformations. We demonstrate an example hierarchical-relational mapping and subsequent migration of relational data induced by hierarchical format evolution.
Read moreAN ALGORITHM FOR NONCONVEX PROGRAMMING
: The paper presents an algorithm to solve the most general mathematical programming problem: s.t. (g superscript i)(y) = or < 0, i = 1,2,. ..,m, Min. g(y), y = (y1,...,yn). The only restriction required is that the functions g superscript i, g be real valued. The general formulation allows for nonlinear or linear integer programming, mixed integer programming and general nonconvex continuous variable programming. The classical approaches have been essentially 'local' or 'neighborhood' techniques dependent on derivatives (or finite difference approximations to derivatives). They suffer from two serious difficulties which can be characterized as the 'dimensionality problem' and the problem of 'trapping at local optima.' Our central aim here is to present a new framework for reaching global optimum. The procedure involves two interconnected mechanisms, a method for structuring the search and a decision rule for selecting the course of the search.
Read moreSpecialising Simulator Generators for High-Performance Monte-Carlo Methods
We address the tension between software generality and performance in the domain of simulations based on Monte-Carlo methods. We simultaneously achieve generality and high performance by a novel development methodology and software architecture centred around the concept of a specialising simulator generator. Our approach combines and extends methods from functional programming, generative programming, partial evaluation, and runtime code generation. We also show how to generate parallelised simulators. We evaluated our approach by implementing a simulator for advanced forms of polymerisation kinetics. We achieved unprecedented performance, making Monte-Carlo methods practically useful in an area that was previously dominated by deterministic PDE solvers. This is of high practical relevance, as Monte-Carlo simulations can provide detailed microscopic information that cannot be obtained with deterministic solvers.
Read moreIntroducing Constraint Functional Logic Programming
A new declarative programming paradigm, constraint functional logic programming (CFLP) is presented, which unifies systematically all features of constraint, functional and logic programming. CFLP extends constraint functional programming (CFP), which supports equation solving over a functional program, to general constraint programming permitting the use of constraints for programming as well as for posing queries. It also generalises constraint logic programming (CLP), by admitting user-defined functions as a purely functional subsystem of a CLP language. This paper presents the motivation for designing CFLP and its semantics. Programming examples are given in the concrete CFLP language Falcon.KeywordsLogic ProgramLogic ProgrammingConstraint ProgrammingConstraint SystemFunctional ProgrammingThese keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.
Read moreAn Introduction to iTasks: Defining Interactive Work Flows for the Web
In these lecture notes we present the iTasks system: a set of combinators to specify work flows in a pure functional language at a very high level of abstraction. Work flow systems are automated systems in which tasks are coordinated that have to be executed by either humans or computers. The combinators that we propose support work flow patterns commonly found in commercial work flow systems. In addition, we introduce novel work flow patterns that capture real world requirements, but that can not be dealt with by current systems. Compared with most of these commercial systems, the iTasks system offers several further advantages: tasks are statically typed, tasks can be higher order, the combinators are fully compositional, dynamic and recursive work flows can be specified, and last but not least, the specification is used to generate an executable web-based multi-user work flow application. With the iTasks system, useful work flows can be defined which cannot be expressed in other systems: a work can be interrupted and subsequently directed to other workers for further processing. The iTasks system has been constructed in the programming language Clean, making use of its generic programming facilities, and its iData toolkit with which interactive, thin-client, form-based web applications can be created. In all, iTasks are an excellent case of the expressive power of functional and generic programming.
Read moreCooperation of Algebraic Constraint Domains in Higher-Order Functional and Logic Programming
This paper presents a theoretical framework for the integration of the cooperative constraint solving of several algebraic domains into higher-order functional and logic programming on λ-abstractions, using an instance of a generic Constraint Functional Logic Programming (CFLP) scheme over a so-called higher-order coordination domain. We provide this framework as a powerful computational model for the higherorder cooperation of algebraic constraint domains over real numbers and integers, which has been useful in practical applications involving the hybrid combination of its components, so that more declarative and efficient solutions can be promoted. Our proposal of computational model has been proved sound and complete with respect to the declarative semantics provided by the CFLP scheme, and enriched with new mechanisms for modeling the intended cooperation among the algebraic domains and a novel higher-order constraint domain equipped with a sound and complete constraint solver for solving higher-order equations. We argue the applicability of our approach describing a prototype implementation on top of the constraint functional logic system TOY
Read moreConceptual Application of List Theory to Data Structures
Following the approach of defining a set through its characteristic function and a multiset (bag) through its count function, Tripathy, Ghosh and Jena ([3]) introduced the concept of position function to define lists. The new definition has much rigor than the earlier one used in computer science in general and functional programming ([2]) in particular. Several of the concepts in the form of operations, operators and properties have been established in a sequence of papers by Tripathy and his coauthors ([3, 6, 7, 8]. Also, the concepts of fuzzy lists ([4]) and that of intuitionistic fuzzy lists ([5]) have been defined and studied by them. Recently an application to develop list theoretic relational databases and operations on them has been put forth by Tripathy and Gantayat ([9]). In the present article we provide another application of this approach in defining data structures like Stack, Queue and Array. One of the major advantages of this approach is the ease in extending all the concepts for basic lists to the context of fuzzy lists and intuitionistic fuzzy lists. We also illustrate this approach in the present paper.
Read moreParallel Branch-and-Bound Algorithms for General Mixed Integer Programming on the CM-5
This "proof of concept" paper describes parallel solution of general mixed integer programs by a branch-and-bound algorithm on the CM-5 multiprocessing system. It goes beyond prior parallel branch-and-bound work by implementing a reasonably realistic general-purpose mixed integer programming algorithm, as opposed to a specialized method for a narrow class of problems. It shows how to use the capabilities of the CM-5 to produce an efficient parallel implementation employing centrally controlled search, achieving near-linear speedups using 64–128 processors on a variety of difficult problems derived from real applications. In concrete terms, a problem requiring half an hour to solve on a SPARC-2 workstation might be solved in 15–20 seconds, and a problem originally taking a week might be reduced to about an hour. Central search control does have limitations, and some final computational experiments begin to address the merits of more decentralized options.
Read more