Enhancing semantic bidirectionalization via shape bidirectionalizer plug-ins

2013 Journal of functional programming  
and Voigtländer (2009) have introduced two techniques that given a sourceto-view function provide an update propagation function mapping an original source and an updated view back to an updated source, subject to standard consistency conditions. Previously, we developed a synthesis of the two techniques, based on a separation of shape and content aspects . Here, we carry that idea further, reworking the technique of Voigtländer such that any shape bidirectionalizer (based on the work of
more » ... the work of Matsuda et al. or not) can be used as a plug-in, to good effect. We also provide a data-type-generic account, enabling wider reuse, including the use of pluggable bidirectionalization itself as a plug-in. ZU064-05-FPR EnhancingSemanticBidirectionalizationViaShapeBidirectionalizerPlugIns 26 August 2013 11:39 2 J. Voigtländer et al. Functional programming approaches have had an important impact, with several ideas and solutions springing from this part of the programming languages field in particular (Bohannon et al. Automatic bidirectionalization is one approach to obtaining suitable get/put-pairs; others are domain-specific languages or more ad-hoc programming techniques. Two different flavors of bidirectionalization have been proposed: syntactic and semantic. Syntactic bidirectionalization (Matsuda et al. 2007) works on a syntactic representation of (somehow restricted) get-functions and synthesizes appropriate definitions for put-functions algorithmically. Semantic bidirectionalization (Voigtländer 2009) does not inspect the syntactic definitions of get-functions at all, but instead provides a single definition of put, parameterized over get as a semantic object, that does the job by invoking get in a kind of "simulation mode". Both syntactic and semantic bidirectionalization have their strengths and weaknesses. Syntactic bidirectionalization heavily depends on syntactic restraints exercised when implementing the get-function. Basically, the technique of Matsuda et al. ( 2007) can only deal with programs in a custom first-order language subject to certain restrictions concerning variable use and nested function calls. Semantic bidirectionalization, in contrast, provides very easy access to bidirectionality within a general-purpose language, liberated from the syntactic corset as to how to write functions of interest. The price to pay for this in the case of the approach of Voigtländer (2009) is that it works for polymorphic functions only, and in the original form is unable to deal with view updates that change the shape of a data structure. The syntactic approach, on the other hand, is successful for many such shapechanging updates, and can deal with non-polymorphic functions. developed an approach for combining syntactic and semantic bidirectionalization. The resulting technique inherits the limitations in program coverage from both techniques, but gains improved updateability: more (s, v ) pairs can successfully be mapped to a suitable s by put (see the next section for a more formal conceptualization). Specifically, semantic bidirectionalization now gets a chance to deal with shape-changing updates, and the combined technique is superior to syntactic bidirectionalization on its own in many cases (and actually never worse than the better of the two original techniques). The combination strategy we pursued was essentially motivated by combining the specialties of the two approaches. Semantic bidirectionalization's specialty is to employ polymorphism to deal with the content elements of data structures in a very lightweight way. In fact, in the original technique, the shape and content aspects of a data structure are completely separated, updates affecting the shape are completely outlawed, arbitrary updates to content elements can be simply absorbed, and by recombining original shape with updated content the desired update consistency is guaranteed. Syntactic bidirectionalization's specialty is to have a more refined, and case-by-case, notion of what updates, including updates on the shape aspect, can be permitted. But it turns out that content elements often get in the way. In fact, by having to deal with both shape and content, at the same time, in the key step of syntactic bidirectionalization (namely "view complement derivation"), updateability is hampered. In our combined approach we divided the labor: semantic bidirectionalization deals with content only, syntactic bidirectionalization deals with shape only. As a result, ZU064-05-FPR EnhancingSemanticBidirectionalizationViaShapeBidirectionalizerPlugIns
doi:10.1017/s0956796813000130 fatcat:3sruid5lubdypktlac7uwizy7i