Bidirectionalization for free! (Pearl)

  • Authors:
  • Janis Voigtländer

  • Affiliations:
  • Technische Universität Dresden, 01062 Dresden, Germany

  • Venue:
  • Proceedings of the 36th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages
  • Year:
  • 2009

Quantified Score

Hi-index 0.00

Visualization

Abstract

A bidirectional transformation consists of a function get that takes a source (document or value) to a view and a function put that takes an updated view and the original source back to an updated source, governed by certain consistency conditions relating the two functions. Both the database and programming language communities have studied techniques that essentially allow a user to specify only one of get and put and have the other inferred automatically. All approaches so far to this bidirectionalization task have been syntactic in nature, either proposing a domain-specific language with limited expressiveness but built-in (and composable) backward components, or restricting get to a simple syntactic form from which some algorithm can synthesize an appropriate definition for put. Here we present a semantic approach instead. The idea is to take a general-purpose language, Haskell, and write a higher-order function that takes (polymorphic) get-functions as arguments and returns appropriate put-functions. All this on the level of semantic values, without being willing, or even able, to inspect the definition of get, and thus liberated from syntactic restraints. Our solution is inspired by relational parametricity and uses free theorems for proving the consistency conditions. It works beautifully.