Compiling Successor ML Pattern Guards John Reppy Mona Zahir University of Chicago University of Chicago USA USA
[email protected] [email protected] 1 Introduction 2 Successor ML Pattern Guards Successor ML [SML15] is a collection of proposed language As mentioned above, Successor ML extends the Standard extensions to the 1997 Definition of StandardMTHM97 ML[ ]. ML pattern syntax with pattern guards, which have the form A number of these extensions address pattern matching, by “p with p0 = e.” The semiformal semantics of this con- adding richer record patterns, or-patterns, and pattern guards; struct is given by the following inference rules: the last of these features is the focus of this paper. s0; E;v ` p ) FAIL; s1 Languages, such as Haskell, OCaml, and Scala, have a 0 restricted form of conditional patterns, where the guards are s0; E;v ` p with p = e ) FAIL; s1 part of the match or case syntax. Compiling such guards is s0; E;v ` p ) VE1; s1 fairly straightforward [Pet99b]. The pattern guards of Succes- 0 0 0 s1; E + VE1 ` e ) v ; s2 s2; E + VE1;v ` p ) FAIL; s3 sor ML are more general, since they are a syntactic form of ; ; ` with 0 = ) FAIL; pattern and, thus, can be nested inside other pattern constructs. s0 E v p p e s3 This more general version of pattern guards allows another s0; E;v ` p ) VE1; s1 1 0 0 0 extension, called transformation patterns, to be defined as a s1; E + VE1 ` e ) v ; s2 s2; E + VE1;v ` p ) VE2; s3 derived form [Ros08], but it also raises some interesting im- 0 s0; E;v ` p with p = e ) E + VE2; s3 plementation issues that have not been previously addressed where s is a state, VE is a value environment, and v is a value.