An Exercise in Polytypic Program Derivation: repmin

نویسنده

  • Oege de Moor
چکیده

A program derivation is said to be polytypic if some of its parameters are data types. The repmin problem is to replace all elements of a tree of numbers by the minimum element, making only a single pass over the original tree. Here we present a polytypic derivation for that problem. The derivation has an unusual feature: when interpreted in the category of relations, the resulting program is the well-known cyclic logic program, and when interpreted in the category of functions, it is the well-known higher-order functional solution. 1 Motivation Suppose I were to show you a derivation of a shortest path algorithm, and my whole presentation was in terms of numbers, addition and minimum. Undoubtedly some of you would get up and point out that by abstracting over the operations and recording their algebraic properties, I could have derived a whole class of algorithms instead of one particular program. Indeed, such abstraction over operations is now commonly accepted as one of the hallmarks of good program derivation: generality is increased, and the presentation is not cluttered by irrelevant particularities. The purpose of this paper is to persuade you that similar beneets can be reaped by abstracting over type constructors. For concreteness, consider the well-known repmin problem 3]: it is required to change a tree t into a tree of the same shape as t, but with all elements replaced by the minimum element. There is a simple program to do that: rst nd the minimum, and then do the replacement. That simple program does however consist of two passes over the original tree t. The challenge is, therefore, to give a program that achieves the same eeect in a single pass.

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

ثبت نام

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

منابع مشابه

What is a data type ?

A program derivation is said to be polytypic if some of its parameters are data types. Polytypic program derivations necessitate a general, non-inductive deenition of`data type'. Here we propose such a dee-nition: a data type is a relator that has membership. It is shown how this deenition implies various other properties that are shared by all data types. In particular, all data types have a u...

متن کامل

Beyond Fun: Order and Membership in Polytypic Imperative Programming

We argue that the category of transformers of monotonic predicates on posets is superior to the category of transformers on pow-ersets, as the basis for a calculus of higher order imperative programming. We show by an example polytypic program derivation that such transformers (and the underlying categories of order-compatible relations and monotonic functions) model a calculus quite similar to...

متن کامل

Under consideration for publication in J . Functional Programming 1 Container Types

A program derivation is said to be polytypic if some of its parameters are data types. Often these data types are container types, whose elements store data. Polytypic program derivations necessitate a general, non-inductive deenition of`container (data) type'. Here we propose such a deenition: a container type is a relator that has membership. It is shown how this deenition implies various oth...

متن کامل

Towards squiggly refinement algebra

The algebra of functions and relations has been used so successfully in program construction that textbooks have appeared. Despite the importance of predicate transformers in imperative programming, the algebra of transformers has been less explored. To show its promise, we prove results on exponents and recursion on inductive data types, sufficient for carrying out a polytypic derivation that ...

متن کامل

Formal polytypic programs and proofs

The aim of our work is to be able to do fully formal, machine verified proofs over Generic Haskellstyle polytypic programs. In order to achieve this goal, we embed polytypic programming in the proof assistant Coq and provide an infrastructure for polytypic proofs. Polytypic functions are reified within Coq as a datatype and they can then be specialized by applying a dependently typed term speci...

متن کامل

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


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

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

ثبت نام

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

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

دوره   شماره 

صفحات  -

تاریخ انتشار 1996