Book of Abstracts - IRIT
Book of Abstracts - IRIT
Book of Abstracts - IRIT
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Mendler-style Recursion Schemes for<br />
Mixed-Variant Datatypes<br />
Ki Yung Ahn 1 , Tim Sheard 1 and Marcelo Fiore 2<br />
1 Portland State University ∗<br />
2 University <strong>of</strong> Cambridge<br />
The context <strong>of</strong> our work is the Nax project. Our goal is to develop a language system, called<br />
Nax, which supports the merits <strong>of</strong> both functional programming languages and formal reasoning<br />
systems based on the Curry–Howard correspondence. Our approach towards these goals is to<br />
design an appropriate foundational calculus [3] that extends F ω [5] (or Fix ω [1] similarly) to justify<br />
the theory <strong>of</strong> Mendler-style recursion schemes [6] with term-indexed datatypes.<br />
In this abstract, we outline a paper that will 1○ discuss the advantages <strong>of</strong> the Mendler<br />
style, 2○ report that we can define an evaluator for the simply-typed HOAS using Mendlerstyle<br />
iteration with syntactic inverses (msfit), and 3○ propose a new recursion scheme (work<br />
in progress) whose termination relies on the invariants specified by size measures on indices.<br />
Advantages <strong>of</strong> the Mendler style include allowing arbitrary definition <strong>of</strong> recursive datatypes,<br />
while still ensuring well-behaved use by providing a rich set <strong>of</strong> principled eliminators. Certain<br />
concepts, such as HOAS, are most succinctly defined as mixed-variant datatypes, which are<br />
unfortunately, outlawed in many existing reasoning systems (e.g., Coq, Agda). One is forced<br />
to devise clever encodings [4], to use concepts like HOAS within such systems.<br />
In functional programming languages, for instance, in Haskell, a HOAS for the untyped<br />
λ-calculus can be defined as data Exp = Abs (Exp -> Exp) | App Exp Exp . Even if we assume all<br />
functions embedded in Abs are non-recursive, evaluating HOAS may still cause problems for<br />
logical reasoning, since the untyped λ-calculus has diverging terms. However, there are many<br />
well-behaved (i.e., terminating) computations on Exp, such as converting an HOAS expression<br />
to first-order syntax. Ahn and Sheard [2] formalized a Mendler-style recursion scheme (msfit,<br />
a.k.a. msfcata) that captures these well-behaved computations.<br />
If the datatype Exp had indexes to assert invariants <strong>of</strong> well-formed expressions, we could rely<br />
on these invariants to write even more expressive programs, such as a terminating well-typed<br />
evaluator. Discussion around this idea will constitute the latter parts <strong>of</strong> the paper.<br />
A simply-typed HOAS evaluator can be defined using msfit at kind * -> *. Since msfit<br />
terminates for any datatype, we are also proving that the evaluation <strong>of</strong> the simply-typed λ-<br />
calculus always terminates just by defining eval : Exp t -> Id t in Nax, as below. We wonder<br />
eval has similarities to other normalization strategies like NbE [7].<br />
data E : (* -> *) -> (* -> *) where -- the "deriving fixpoint Exp" defines<br />
Abs : (r a -> r b) -> E r (a -> b) -- abs f = In[* -> *] (Abs f)<br />
App : E r (a -> b) -> E r a -> E r b -- app f e = In[* -> *] (App f e)<br />
deriving fixpoint Exp -- synonym Exp t = Mu[* -> *] E t<br />
data Id a = MkId a -- the identity type<br />
unId (MkId x) = x -- destructor <strong>of</strong> Id<br />
eval e = msfit { t . Id t } e with<br />
call inv (App f x) = MkId (unId(call f) (unId(call x)))<br />
call inv (Abs f) = MkId (\v -> unId(call (f (inv (MkId v)))))<br />
∗ supported by NSF grant 0910500.<br />
18