We propose an imperative version of the Rewriting Calculus, a calculus based on pattern matching, pattern abstraction and side effects, which we call iRho. We formulate both a static and big-step call-by-value operational semantics of iRho. The operational semantics is deterministic, and immediately suggests how an interpreter for the calculus may be built. The static semantics is given using a first-order type system based on a form of product types, which can be assigned to term-like structures (that is, records). The calculus isà la Church, that is, pattern abstractions are decorated with the types of the free variables of the pattern. iRho is a good candidate for the core of a pattern-matching imperative language, where a (monomorphic) typed store can be safely manipulated and where fixed points are built into the language itself. Properties such as determinism of the interpreter and subject-reduction have been completely checked using a machine-assisted approach with the Coq proof assistant. Progress and decidability of type checking are proved using pen and paper.
IntroductionThe study of rewriting-based languages (such as Elan Although rewriting-based languages are less popular than object-oriented languages such as Java (Sun 2005) and C# (Microsoft 2005) for ordinary programming, they can serve as common typed intermediate languages for implementing compilers for rewritingbased, functional, object-oriented, logic, and other high-level modern languages (Cirstea et al. 2001a;Cirstea et al. 2002;Cirstea et al. 2004).Pattern matching has been used widely in functional and logic programming (for example, in ML (Milner et al. 1997;Cristal Team 2005), Haskell (Jones 2003), Scheme (R. Kelsey 1998), Curry (Hanus 1997) and Prolog (Kowalski 1979)), but it has generally been considered to be a convenient mechanism for expressing complex requirements about the function's argument, rather than as a basis for an ad hoc paradigm of computation.One of the main advantages of rewriting-based languages is pattern matching, which allows one to discriminate between alternatives. These languages permit non-determinism in the sense that they can represent a collection of results. That is, pattern matching need not be exclusive, multiple branches can be 'fired' simultaneously. An empty collection of L. Liquori and B. P. Serpette 2 results represents an application failure, a singleton represents a deterministic result, and a collection with more than one element represents a non-deterministic choice between the elements of the collection.This feature highlights a difference compared with those functional languages featuring pattern matching, such as ML, Haskell and Scheme. It shares some similarities with backtracking and exhaustive proof search in logic languages like Prolog. It is possible to make a pair of two functions having the same pattern, and when the pair is applied to an argument, both functions will be fired. Optimistic and pessimistic operational semantics † , with a fixed strategy, can then be imposed on the langua...