## A type system for well-founded recursion (2004)

### Cached

### Download Links

- [reports-archive.adm.cs.cmu.edu]
- [www.cs.cmu.edu]
- [www-2.cs.cmu.edu]
- [www.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [www.mpi-sws.org]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- [reports-archive.adm.cs.cmu.edu]
- DBLP

### Other Repositories/Bibliography

Venue: | In 31st symp. Principles of Progr. Lang |

Citations: | 31 - 6 self |

### BibTeX

@INPROCEEDINGS{Dreyer04atype,

author = {Derek Dreyer and Robert Harper and Karl Crary},

title = {A type system for well-founded recursion},

booktitle = {In 31st symp. Principles of Progr. Lang},

year = {2004},

pages = {293--305},

publisher = {ACM Press}

}

### Years of Citing Articles

### OpenURL

### Abstract

In the interest of designing a recursive module extension to ML that is as simple and general as possible, we propose a novel type system for general recursion over effectful expressions. The presence of effects seems to necessitate a backpatching semantics for recursion based on Scheme’s. Our type system ensures statically that recursion is well-founded (that the body of a recursive expression will evaluate without attempting to access the undefined recursive variable), which avoids some unnecessary run-time costs associated with backpatching. To ensure well-founded recursion in the presence of multiple recursive variables and separate compilation, we track the usage of individual recursive variables, represented statically by “names”. So that our type system may eventually be integrated smoothly into ML’s, reasoning involving names is only required inside code that uses our recursive construct and does not need to infect existing ML code. This material is based on work supported in part by NSF grants CCR-9984812 and CCR-0121633. Any opinions, findings, and conclusions or recommendations in this publication are those of the author(s) and do not reflect the views of this agency.

### Citations

267 | A type-theoretic approach to higher-order modules with sharing - Harper, Lillibridge - 1994 |

188 | Units: Cool modules for HOT languages - Flatt, Felleisen - 1998 |

92 | Simple imperative polymorphism - Wright - 1995 |

43 | Recursive monadic bindings - Erkök, Launchbury - 2000 |

18 | Mixin modules and computational effects - Ancona, Fagorzi, et al. |

18 | and Constantinos Sourelis. Mixin modules - Duggan |

2 | Mixin modules and computational eects - Ancona, Fagorzi, et al. - 2003 |

1 |
x : τ, Γ ′ ⊢ e ′ : τ ′ [S] and Γ ⊢ e : τ [T
- If
(Show Context)
Citation Context ...alization section. There have also been several proposals based on Ancona and Zucca’s calculus CMS for purely functional call-by-name mixin modules [2]. In one direction, recent work by Ancona et al. =-=[1]-=- extends CMS with computational effects encapsulated by monads. They handle recursive monadic computations using a recursive do construct based on Erkök and Launchbury’s [10]. In another direction, Hi... |

1 |
x : τ1, Γ ′ ⊢ e : τ [S] and Γ
- If
(Show Context)
Citation Context ...le than one that forbids effects entirely, it imposes a structure on recursive modules that is rather arbitrary. Others have suggested abandoning ML-style modules altogether in favor of mixin modules =-=[2, 15]-=- or units [11], for which recursive linking is the norm and hierarchical linking a special case. For the purpose of extending ML, though, this would constitute a rather drastic revision of the languag... |

1 |
τ1 ≡S τ2 and T ⊆ dom(Γ), then Γ, Γ ′ [T/X] ⊢ τ1[T/X] ≡ S[T/X] τ2[T/X]. Proof: By straightforward induction on the derivation of the first premise. The invariant T
- If, X
(Show Context)
Citation Context ... dom(Γ) Γ ⊢ x : Γ(x) [S] (1) Γ ⊢ e1 : τ1 [S] Γ ⊢ e2 : τ2 [S] Γ ⊢ 〈e1, e2〉 : τ1 × τ2 [S] (3) Γ, x : σ ⊢ e : τ [S ∪ T] Γ ⊢ λx. e : σ T −→ τ [S] Γ ⊢ 〈〉 : 1 [S] (2) Γ ⊢ e : τ1 × τ2 [S] Γ ⊢ πi(e) : τi [S] =-=(5)-=- Γ ⊢ f : σ T −→ τ [S] Γ ⊢ e : σ [S] T ⊆ S Γ ⊢ f(e) : τ [S] Γ, X ⊢ e : τ [S] Γ ⊢ λX. e : ∀X. τ [S] (7) Γ ⊢ e : τ [S] Γ ⊢ box(e) : boxT(τ) [S] (9) (6) Γ ⊢ f : ∀X. τ [S] Γ ⊢ f(T) : τ[T/X] [S] (8) Γ ⊢ e :... |

1 |
Γ ⊢ vi : τi [S]. • Case: Rule 23
- Inversion
(Show Context)
Citation Context ...le than one that forbids effects entirely, it imposes a structure on recursive modules that is rather arbitrary. Others have suggested abandoning ML-style modules altogether in favor of mixin modules =-=[2, 15]-=- or units [11], for which recursive linking is the norm and hierarchical linking a special case. For the purpose of extending ML, though, this would constitute a rather drastic revision of the languag... |

1 |
Γ ⊢ e[v/x] : τ [S]. • Case: Rule 26
- Substitution
(Show Context)
Citation Context ...tore ω is well-formed, denoted Γ ⊢ ω [S], if Γ ⊢ ω [S] according to Definition 4.2 and also: • ∀x : comp T(τ) ∈ Γ. either ω(x) = ? or Γ ⊢ ω(x) : τ [S ∪ T] 6 Related Work Well-Founded Recursion Boudol =-=[3]-=- proposes a type system for well-founded recursion that, like ours, employs a backpatching semantics. Boudol’s system tracks the degrees to which expressions depend on their free variables, where the ... |

1 |
Γ ⊢ e : ∀X. σ [S] and Γ ⊢ τ ≡S σ[T/X
- Inversion
(Show Context)
Citation Context ...le than one that forbids effects entirely, it imposes a structure on recursive modules that is rather arbitrary. Others have suggested abandoning ML-style modules altogether in favor of mixin modules =-=[2, 15]-=- or units [11], for which recursive linking is the norm and hierarchical linking a special case. For the purpose of extending ML, though, this would constitute a rather drastic revision of the languag... |

1 |
Γ ⊢ e[T/X] : τ[T/X] [S]. • Case: Rule 28
- Substitution
(Show Context)
Citation Context ...tore ω is well-formed, denoted Γ ⊢ ω [S], if Γ ⊢ ω [S] according to Definition 4.2 and also: • ∀x : comp T(τ) ∈ Γ. either ω(x) = ? or Γ ⊢ ω(x) : τ [S ∪ T] 6 Related Work Well-Founded Recursion Boudol =-=[3]-=- proposes a type system for well-founded recursion that, like ours, employs a backpatching semantics. Boudol’s system tracks the degrees to which expressions depend on their free variables, where the ... |

1 |
Γ ⊢ e : σ [S], where Γ ⊢ τ ≡S boxT(σ
- Inversion
(Show Context)
Citation Context |

1 |
x : boxT(τ) ⊢ ω[x ↦→ v] [S] and Γ, x : boxT(τ) ⊢ C : boxT(τ) cont [S
- Weakening, Γ
(Show Context)
Citation Context |

1 |
x : boxT(τ) ⊢ x : boxT(τ
- Rule
(Show Context)
Citation Context ...tore ω is well-formed, denoted Γ ⊢ ω [S], if Γ ⊢ ω [S] according to Definition 4.2 and also: • ∀x : comp T(τ) ∈ Γ. either ω(x) = ? or Γ ⊢ ω(x) : τ [S ∪ T] 6 Related Work Well-Founded Recursion Boudol =-=[3]-=- proposes a type system for well-founded recursion that, like ours, employs a backpatching semantics. Boudol’s system tracks the degrees to which expressions depend on their free variables, where the ... |

1 |
x is either bound in Γ as x : boxT(σ) (where T
- Inversion
(Show Context)
Citation Context |

1 |
τ ≡S τ ′ and Γ, X ⊲ x : τ ⊢ e : σ [S] and Γ, X ⊲ x : τ ⊢ σ ≡X τ
- Inversion, Γ
(Show Context)
Citation Context |

1 |
X ⊲ x : τ ⊢ C : τ cont [S
- Weakening, Γ
(Show Context)
Citation Context |

1 |
also by Weakening, Γ ⊢ ω[x := v
- Thus
(Show Context)
Citation Context |

1 |
τ = ref(σ) and Γ ⊢ e : σ [S
- Inversion
(Show Context)
Citation Context |

1 |
x : ref(τ) ⊢ ω[x ↦→ v
- Weakening, Γ
(Show Context)
Citation Context |

1 |
x : ref(τ) ⊢ x : ref(τ
- Rule
(Show Context)
Citation Context |

1 |
x : ref(σ) ∈ Γ, where Γ ⊢ σ ≡S τ
- Inversion
(Show Context)
Citation Context |

1 |
Γ ⊢ τ ≡S τ ′ and Γ, x : cont(τ) ⊢ e : τ [S
- Inversion
(Show Context)
Citation Context |

1 |
x : cont(τ) ⊢ C : τ cont [S] and Γ, x : cont(τ
- Weakening, Γ
(Show Context)
Citation Context |

1 |
Cx : τ cont [S]. • Case: Rule 73. x �∈ dom(ω) (ω; C; delay(e)) ↦→ (ω[x ↦→ e]; C; x
- Thus
(Show Context)
Citation Context |

1 |
x : comp T(σ
- Inversion
(Show Context)
Citation Context |

1 |
If τ is anything else, v is a variable x. ω(x) = ? (ω; C ◦ force(•); x) ↦→ Error Proof: Straightforward. Theorem A.9 (Progress) If Γ ⊢ Ω [S], then either Ω is terminal or there exists Ω ′ such that Ω ↦→ Ω ′ . Proof: If Ω is terminal, then we are done. So
- Γ
(Show Context)
Citation Context ... dom(Γ) Γ ⊢ x : Γ(x) [S] (1) Γ ⊢ e1 : τ1 [S] Γ ⊢ e2 : τ2 [S] Γ ⊢ 〈e1, e2〉 : τ1 × τ2 [S] (3) Γ, x : σ ⊢ e : τ [S ∪ T] Γ ⊢ λx. e : σ T −→ τ [S] Γ ⊢ 〈〉 : 1 [S] (2) Γ ⊢ e : τ1 × τ2 [S] Γ ⊢ πi(e) : τi [S] =-=(5)-=- Γ ⊢ f : σ T −→ τ [S] Γ ⊢ e : σ [S] T ⊆ S Γ ⊢ f(e) : τ [S] Γ, X ⊢ e : τ [S] Γ ⊢ λX. e : ∀X. τ [S] (7) Γ ⊢ e : τ [S] Γ ⊢ box(e) : boxT(τ) [S] (9) (6) Γ ⊢ f : ∀X. τ [S] Γ ⊢ f(T) : τ[T/X] [S] (8) Γ ⊢ e :... |

1 |
1 S 2 and T dom(), then ; [T=X] ` 1 [T=X] S[T=X] 2 [T=X]. Proof: By straightforward induction on the derivation of the premise. The invariant T
- If
(Show Context)
Citation Context ...2 dom() ` x : (x) [S] (1) ` hi : 1 [S] (2) ` e 1 : 1 [S] ` e 2 : 2 [S] ` he 1 ; e 2 i : 1 2 [S] (3) ` e : 1 2 [S] ` i (e) : i [S] (4) ; x : ` e : [S [ T] ` x: e : T ! [S] (5) ` f : T ! [S] ` e : [S] T S ` f(e) : [S] (6) ; X ` e : [S] ` X: e : 8X: [S] (7) ` f : 8X: [S] ` f(T) : [T=X] [S] (8) ` e : [S] ` box(e) : boxT () [S] (9) ` e : boxT () [S] T S... |

1 |
v i : i [S]. Case: Rule 23
- Inversion
(Show Context)
Citation Context ...ble than one that forbids eects entirely, it imposes a structure on recursive modules that is rather arbitrary. Others have suggested abandoning ML-style modules altogether in favor of mixin modules [=-=2, 15]-=- or units [11], for which recursive linking is the norm and hierarchical linking a special case. For the purpose of extending ML, though, this would constitute a rather drastic revision of the languag... |

1 |
e[v=x] : [S]. Case: Rule 26
- Substitution
(Show Context)
Citation Context ...ss) A store ! is well-formed, denoted ` ! [S], if ` ! [S] according to Denition 4.2 and also: 8x : comp T () 2 : either !(x) = ? or ` !(x) : [S [ T] 6 Related Work Well-Founded Recursion Boudol [3] proposes a type system for well-founded recursion that, like ours, employs a backpatching semantics. Boudol's system tracks the degrees to which expressions depend on their free variables, where the ... |

1 |
e[T=X] : [T=X] [S]. Case: Rule 28
- Substitution
(Show Context)
Citation Context ...ss) A store ! is well-formed, denoted ` ! [S], if ` ! [S] according to Denition 4.2 and also: 8x : comp T () 2 : either !(x) = ? or ` !(x) : [S [ T] 6 Related Work Well-Founded Recursion Boudol [3] proposes a type system for well-founded recursion that, like ours, employs a backpatching semantics. Boudol's system tracks the degrees to which expressions depend on their free variables, where the ... |

1 |
C : boxT () cont [S] and ` v
- well-formedness
(Show Context)
Citation Context ...alization section. There have also been several proposals based on Ancona and Zucca's calculus CMS for purely functional call-by-name mixin modules [2]. In one direction, recent work by Ancona et al. =-=[-=-1] extends CMS with computational eects encapsulated by monads. They handle recursive monadic computations using a recursive do construct based on Erkok and Launchbury's [10]. In another direction, Hi... |

1 |
x : boxT () ` ![x 7! v
- Weakening
(Show Context)
Citation Context ...ble than one that forbids eects entirely, it imposes a structure on recursive modules that is rather arbitrary. Others have suggested abandoning ML-style modules altogether in favor of mixin modules [=-=2, 15]-=- or units [11], for which recursive linking is the norm and hierarchical linking a special case. For the purpose of extending ML, though, this would constitute a rather drastic revision of the languag... |

1 |
C : cont [S] and ` x : box
- well-formedness
(Show Context)
Citation Context ...alization section. There have also been several proposals based on Ancona and Zucca's calculus CMS for purely functional call-by-name mixin modules [2]. In one direction, recent work by Ancona et al. =-=[-=-1] extends CMS with computational eects encapsulated by monads. They handle recursive monadic computations using a recursive do construct based on Erkok and Launchbury's [10]. In another direction, Hi... |

1 |
x is either bound in as x : boxT () (where T
- Inversion
(Show Context)
Citation Context ...ble than one that forbids eects entirely, it imposes a structure on recursive modules that is rather arbitrary. Others have suggested abandoning ML-style modules altogether in favor of mixin modules [=-=2, 15]-=- or units [11], for which recursive linking is the norm and hierarchical linking a special case. For the purpose of extending ML, though, this would constitute a rather drastic revision of the languag... |

1 |
also by Weakening, ` ![x := v
- Thus
(Show Context)
Citation Context ...ss) A store ! is well-formed, denoted ` ! [S], if ` ! [S] according to Denition 4.2 and also: 8x : comp T () 2 : either !(x) = ? or ` !(x) : [S [ T] 6 Related Work Well-Founded Recursion Boudol [3] proposes a type system for well-founded recursion that, like ours, employs a backpatching semantics. Boudol's system tracks the degrees to which expressions depend on their free variables, where the ... |

1 |
C : ref() cont [S] and ` v
- well-formedness
(Show Context)
Citation Context ...alization section. There have also been several proposals based on Ancona and Zucca's calculus CMS for purely functional call-by-name mixin modules [2]. In one direction, recent work by Ancona et al. =-=[-=-1] extends CMS with computational eects encapsulated by monads. They handle recursive monadic computations using a recursive do construct based on Erkok and Launchbury's [10]. In another direction, Hi... |

1 |
C : cont [S] and ` x : ref
- well-formedness
(Show Context)
Citation Context |

1 |
x : ref() 2 , where
- Inversion
(Show Context)
Citation Context |

1 |
x : cont() ` C : cont [S] and ; x : cont() ` ![x 7
- Weakening
(Show Context)
Citation Context |

1 |
e 1 : cont
- Inversion
(Show Context)
Citation Context |

1 |
C : cont [S], ` e : [S] and ` v : cont
- well-formedness
(Show Context)
Citation Context |

1 |
C x : cont [S]. Case: Rule 73. x 62 dom(!) (!; C; delay(e)) 7! (![x 7! e]; C; x
- Thus
(Show Context)
Citation Context |

1 |
C : cont [S] and ` x : comp
- well-formedness
(Show Context)
Citation Context |