“Everything Is Everything” Revisited: Shapeshifting Data Types with Isomorphisms and Hylomorphisms (original) (raw)

Isomorphisms, hylomorphisms and hereditarily finite data types in Haskell

Proceedings of the 2009 ACM symposium on Applied Computing, 2009

This paper is an exploration in a functional programming framework of isomorphisms between elementary data types (natural numbers, sets, multisets, finite functions, permutations binary decision diagrams, graphs, hypergraphs, parenthesis languages, dyadic rationals, primes, DNA sequences etc.) and their extension to hereditarily finite universes through hylomorphisms derived from ranking/unranking and pairing/unpairing operations. An embedded higher order combinator language provides any-to-any encodings automatically. Besides applications to experimental mathematics, a few examples of "free algorithms" obtained by transferring operations between data types are shown. Other applications range from stream iterators on combinatorial objects to self-delimiting codes, succinct data representations and generation of random instances. The paper covers 59 data types and, through the use of the embedded combinator language, provides 3540 distinct bijective transformations between them. The self-contained source code of the paper, as generated from a literate Haskell program, is available at http://logic.csci.unt.edu/tarau/ research/2008/fISO.zip. A short, 5 page version of the paper, published as [1] describes the idea of organizing various data transformations as encodings to sequences of natural numbers and gives a few examples of hylomorphisms that lift the encodings to related hereditarily finite universes.

An embedded declarative data transformation language

Proceedings of the 11th ACM SIGPLAN conference on Principles and practice of declarative programming, 2009

We introduce a logic programming framework for data type transformations based on isomorphisms between elementary data types (natural numbers, finite functions, sets and permutations, digraphs, hypergraphs, etc.) and automatically derived extensions to hereditarily finite universes through ranking/unranking operations. An embedded higher order combinator language provides anyto-any encodings automatically. Applications range from stream iterators on combinatorial objects and uniform generation of random instances to succinct data representations and serialization of Prolog terms.

Ranking Catamorphisms and Unranking Anamorphisms on Hereditarily Finite Datatypes

2008

Using specializations of unfold and fold on a generic tree data type we derive unranking and ranking functions providing natural number encodings for various Hereditarily Finite datatypes. In this context, we interpret unranking operations as instances of a generic anamorphism and ranking operations as instances of the corresponding catamorphism. Starting with Ackerman's Encoding from Hereditarily Finite Sets to Natural Numbers we define pairings and finite tuple encodings that provide building blocks for a theory of Hereditarily Finite Functions. The more difficult problem of ranking and unranking Hereditarily Finite Permutations is then tackled using Lehmer codes and factoradics. The self-contained source code of the paper, as generated from a literate Haskell program, is available at http:// logic.csci.unt.edu/tarau/research/2008/fFUN.zip.

Elements of a relational theory of datatypes

Lecture Notes in Computer Science, 1993

The \Boom hierarchy" is a hierarchy of types that begins at the level of trees and includes lists, bags and sets. This hierarchy forms the basis for the calculus of total functions developed by Bird and Meertens, and which has become known as the \Bird-Meertens formalism". This paper describes a hierarchy of types that logically precedes the Boom hierarchy. We show how the basic operators of the Bird-Meertens formalism (map, reduce and lter) can be introduced in a logical sequence by beginning with a very simple structure and successively re ning that structure.

A functional hitchhiker's guide to hereditarily finite sets, Ackermann encodings and pairing functions

2008

The paper is organized as a self-contained literate Haskell program that implements elements of an executable finite set theory with focus on combinatorial generation and arithmetic encodings. The code, tested under GHC 6.6.1, is available at http://logic.csci.unt.edu/tarau/ research/2008/fSET.zip. We introduce ranking and unranking functions generalizing Ackermann's encoding to the universe of Hereditarily Finite Sets with Urelements. Then we build a lazy enumerator for Hereditarily Finite Sets with Urelements that matches the unranking function provided by the inverse of Ackermann's encoding and we describe functors between them resulting in arithmetic encodings for powersets, hypergraphs, ordinals and choice functions. After implementing a digraph representation of Hereditarily Finite Sets we define decoration functions that can recover well-founded sets from encodings of their associated acyclic digraphs. We conclude with an encoding of arbitrary digraphs and discuss a concept of duality induced by the set membership relation.

Computation on abstract data types. The extensional approach, with an application to streams

In this paper we specialize the notion of abstract computational procedure previously introduced for intensionally presented structures to those which are extensionally given. This is provided by a form of generalized recursion theory which uses schemata for explicit definition, conditional definition and least fixed point (LFP) recursion in functionals of type level ≤ 2 over any appropriate structure. It is applied here to the case of potentially infinite (and more general partial) streams as an abstract data type.

Compositional data types

2011

Building on Wouter Swierstra's Data typesà la carte, we present a comprehensive Haskell library of compositional data types suitable for practical applications. In this framework, data types and functions on them can be defined in a modular fashion. We extend the existing work by implementing a wide array of recursion schemes including monadic computations. Above all, we generalise recursive data types to contexts, which allow us to characterise a special yet frequent kind of catamorphisms. The thus established notion of term homomorphisms allows for flexible reuse and enables shortcut fusion style deforestation which yields considerable speedups. We demonstrate our framework in the setting of compiler construction, and moreover, we compare compositional data types with generic programming techniques and show that both are comparable in run-time performance and expressivity while our approach allows for stricter types. We substantiate this conclusion by lifting compositional data types to mutually recursive data types and generalised algebraic data types. Lastly, we compare the run-time performance of our techniques with traditional implementations over algebraic data types. The results are surprisingly good.

Generic Programming with Combinators and Objects

ArXiv, 2021

We present a generic programming framework for OCAML which makes it possible to implement extensible transformations for a large scale of type definitions. Our framework makes use of objectoriented features of OCAML, utilising late binding to override the default behaviour of generated transformations. The support for polymorphic variant types complements the ability to describe composable data types with the ability to implement composable transformations.

On computing with types

Proceedings of the 27th Annual ACM Symposium on Applied Computing, 2012

We express in terms of binary trees seen as Gödel System T types (with the empty type as the only primitive type) arithmetic computations within time and space bounds comparable to binary arithmetic and derive an efficiently testable total ordering on types, isomorphic to the ordering of natural numbers. A few novel algorithms are derived in the process, that enable arithmetic computations with type trees. The use of a Haskell type class describing the "axiomatization" of the shared structure present in System T's type language and natural numbers, together with Haskell instances representing "twin" interpretations connected by an iso-functor that transports operations between the two instances, provides instant empirical testability.

Fine Hierarchies of Generic Computation

International Conference on Database Theory, 1997

Suppose that you are a user of a commercial relational database, accessible over the Internet, whose owner has decided to copy the price lists of the US telephone companies — first order queries are for free just like local calls, because they are local by the theorem of Gaifman These are the rules. Well, what is your strategy, to compute all you want to know about the database, paying as little as possible? And how much will the total price be? We answer this question, showing that the question whether you can get your answer without any costs at all, depends on whether or not the theories of databases in the provided query language are finitely axiomatizable. Thus, assuming there is a limit on the number of variables allowed in queries, if the database query language is the fixpoint logic, you can get everything for free. When it is Datalog however, even with inequality and negation of the edb's, you have to pay. We present a method, which for graphs of n vertices costs about $ log2 log2 n. Thus querying a graph with 1 Terabyte vertices costs $7.00. We demonstrate that this price cannot be substantially reduced without causing a large computational overhead.