Figure 9: Subtyping Algorithm Algorithmic subtyping rules E ⊢ × db S
Figure 10: Subtyping Algorithm Statistics Lines Without √ Prover With √ Prover Benchmark <strong>of</strong> code ? × ? × arith.sage 45 132 13 0 145 0 0 bst.sage 62 344 28 0 372 0 0 heap.sage 69 322 34 0 356 0 0 mergesort.sage 80 437 31 0 468 0 0 polylist.sage 397 2338 5 0 2343 0 0 printf.sage 228 321 1 0 321 1 0 regexp.sage 113 391 2 0 391 2 0 stlc.sage 227 677 11 0 677 11 0 Total 1221 4962 125 0 5073 14 0 type judgments. Some complicated tests in stlc.sage <strong>and</strong> printf.sage must also be checked dynamically. Despite the use <strong>of</strong> a theorem prover, compilation times for these benchmarks is quite manageable. On a 3GHz Pentium 4 Xeon processor running Linux 2.6.14, compilation required fewer than 10 seconds for each <strong>of</strong> the benchmarks, except for polylist.sage which took approximately 18 seconds. We also measured the number <strong>of</strong> evaluation steps required during each subtype test. We found that 83% <strong>of</strong> the subtype tests required no evaluation, 91% required five or fewer steps, <strong>and</strong> only a h<strong>and</strong>ful <strong>of</strong> the the tests in our benchmarks required more than 50 evaluation steps. 8. Related Work The enforcement <strong>of</strong> complex program specifications, or contracts, is the subject <strong>of</strong> a large body <strong>of</strong> prior work [32, 13, 26, 21, 24, 28, 37, 25, 12, 8]. Since these contracts are typically not expressible in classical type systems, they have previously been relegated to dynamic checking, as in, for example, Eiffel [32]. Eiffel’s expressive contract language is strictly separated from its type system. Hybrid type checking extends contracts with the ability to check many properties at compile time. Meunier et al have also investigated statically verifying contracts via set-based analysis [31]. The static checking tool ESC/Java [17] supports expressive JML specifications [26]. However, ESC/Java’s error messages may be caused either by incorrect programs or by limitations in its own analysis, <strong>and</strong> thus it may give false alarms on correct (but perhaps complicated) programs. In contrast, hybrid type checking only produces error messages for provably ill-typed programs. The Spec# programming system extends C# with expressive specifications [6], including preconditions, postconditions, <strong>and</strong> non-null annotations. Specifications are enforced dynamically, <strong>and</strong> can be also checked statically via a separate tool. The system is somewhat less tightly integrated than in Sage. For example, successful static verification does not automatically remove the corresponding dynamic checks. Recent work on advanced type systems has influenced our choice <strong>of</strong> how to express program invariants. In particular, Freeman <strong>and</strong> Pfenning [18] extended ML with another form <strong>of</strong> refinement types. They work focuses on providing both decidable type checking <strong>and</strong> type inference, instead <strong>of</strong> on supporting arbitrary refinement predicates. Xi <strong>and</strong> Pfenning have explored applications <strong>of</strong> dependent types in Dependent ML [44, 43]. Decidability <strong>of</strong> type checking is preserved by appropriately restricting which terms can appear in types. Despite these restrictions, a number <strong>of</strong> interesting examples can be expressed in Dependent ML. Our system <strong>of</strong> dependent types extends theirs with arbitrary executable refinement predicates, <strong>and</strong> the hybrid type checking infrastructure is designed to cope with the resulting undecidability. In a complementary approach, Chen <strong>and</strong> Xi [10] address decidability limitations by providing a mechanism through which the programmer can provide pro<strong>of</strong>s <strong>of</strong> subtle properties in the source code. Recently, Ou, Tan, M<strong>and</strong>elbaum, <strong>and</strong> Walker developed a dependent type system that leverages dynamic checks [35] in a way similar to Sage. Unlike Sage, their system is decidable, <strong>and</strong> they leverage dynamic checks to reduce the need for precise type annotations in explicitly labeled regions <strong>of</strong> programs. They consider mutable data, which we intend to add to Sage in the future. We are exploring other language features, such as objects [16], as well. Barendregt introduced the unification <strong>of</strong> types <strong>and</strong> terms, which allows types to be flexibly expressed as complex expressions, while simplifying the underlying theory [5]. The language Cayenne adopts this approach <strong>and</strong> copes with the resulting undecidability <strong>of</strong> type checking by allowing a maximum number <strong>of</strong> steps, somewhat like a timeout, before reporting to the user that typing has failed [4]. Hybrid type checking differs in that instead <strong>of</strong> rejecting subtly well-typed programs outright, it provisionally accepts them <strong>and</strong> then performs dynamic checking where necessary. Other authors have considered pragmatic combinations <strong>of</strong> both static <strong>and</strong> dynamic checking. Abadi, Cardelli, Pierce <strong>and</strong> Plotkin [1] extended a static type system with a type Dynamic that could be explicitly cast to <strong>and</strong> from any other type (with appropriate run-time checks). Henglein characterized the completion process <strong>of</strong> inserting the necessary coercions, <strong>and</strong> presented a rewriting system for generating minimal completions [23]. Thatte developed a similar system in which the necessary casts are implicit [39]. For <strong>Scheme</strong>, s<strong>of</strong>t type systems [29, 42, 3, 15] prevent some basic type errors statically, while checking other properties at run time. The limitations <strong>of</strong> purely-static <strong>and</strong> purely-dynamic approaches have also motivated other work on hybrid analyses. For example, CCured [33] is a sophisticated hybrid analysis for preventing the ubiquitous array bounds violations in the C programming language. Unlike our proposed approach, it does not detect errors statically. Instead, the static analysis is used to optimize the run-time analysis. Specialized hybrid analyses have been proposed for other problems as well, such as data race condition checking [41, 34, 2]. 9. Conclusions <strong>and</strong> Future Work Program specifications are essential for modular development <strong>of</strong> reliable s<strong>of</strong>tware. Sage uses a synthesis <strong>of</strong> firstclass types, Dynamic, <strong>and</strong> refinement types to enforce precise specifications in a flexible manner. Our hybrid checking algorithm extends traditional type checking with a theorem prover, a database <strong>of</strong> counter-examples, <strong>and</strong> the ability to insert dynamic checks when necessary. Experimental results show that Sage can verify many correctness properties at compile time. We believe that Sage illustrates a promising approach for reliable s<strong>of</strong>tware development. A number <strong>of</strong> opportunities remain for future work. The benefits <strong>of</strong> the refuted subtype database can clearly be amplified by maintaining a single repository for all local <strong>and</strong> non-local users <strong>of</strong> Sage. We also plan to integrate r<strong>and</strong>omized or directed [20] testing to refute additional validity queries, thereby detecting more errors at compile time. Since precise type inference for Sage is undecidable, we plan to develop hybrid algorithms that infer precise types <strong>Scheme</strong> <strong>and</strong> <strong>Functional</strong> <strong>Programming</strong>, <strong>2006</strong> 103
- Page 1:
Scheme and Functional Programming 2
- Page 4 and 5:
4 Scheme and Functional Programming
- Page 6 and 7:
6 Scheme and Functional Programming
- Page 8 and 9:
• A web browser that plays the ro
- Page 10 and 11:
and requests. When a client request
- Page 12 and 13:
above prevents pages from these dom
- Page 14 and 15:
14 Scheme and Functional Programmin
- Page 16 and 17:
2. Explaining Macros Macro expansio
- Page 18 and 19:
For completeness, here is the macro
- Page 20 and 21:
onment is extended in the original
- Page 22 and 23:
expand-term(term, env, phase) = emi
- Page 24 and 25:
Derivation ::= (make-mrule Syntax S
- Page 26 and 27:
True derivation (before macro hidin
- Page 28 and 29:
We assume that the reader has basic
- Page 30 and 31:
the value of the %eax register by 4
- Page 32 and 33:
Code generation for the new forms i
- Page 34 and 35:
we introduced in 3.11. The only dif
- Page 36 and 37:
the user code from interfering with
- Page 38 and 39:
38 Scheme and Functional Programmin
- Page 40 and 41:
mization and on creating efficient
- Page 42 and 43:
(a) stage (b) fifo (c) split (d) me
- Page 44 and 45:
This tagging is used later in the c
- Page 46 and 47:
(let ((clo_25 (%closure (lambda (y)
- Page 48 and 49:
nb. cycles per element 1400 1200 10
- Page 50 and 51:
50 Scheme and Functional Programmin
- Page 52 and 53: a ∗ ❅ left right · b ❅ a S
- Page 54 and 55: T ([spec], w) = { {w}, if w ∈ L([
- Page 56 and 57: A([spec]): ✓✏ (where L([spec])
- Page 58 and 59: construction commands. It is possib
- Page 60 and 61: ; Regular expression for Scheme num
- Page 62 and 63: References [1] A. V. Aho, R. Sethi,
- Page 64 and 65: (let ((n (cond ((char? var0) ) ((sy
- Page 66 and 67: 3. Survey An incomplete survey of a
- Page 68 and 69: case monster 10 literals 100 litera
- Page 70 and 71: 70 Scheme and Functional Programmin
- Page 72 and 73: modest programming requirements, an
- Page 74 and 75: development of incomplete subsystem
- Page 76 and 77: the previous request. This method a
- Page 78 and 79: could be run indefinitely. This fun
- Page 80 and 81: programmers reject Scheme without r
- Page 82 and 83: (define interp (λ (env e) (case e
- Page 84 and 85: Before describing the run-time sema
- Page 86 and 87: Figure 5. Cast Insertion Figure 6.
- Page 88 and 89: Figure 7. Evaluation Figure 8. Eval
- Page 90 and 91: catching type errors, as we do here
- Page 92 and 93: [34] J. C. Reynolds. Types, abstrac
- Page 94 and 95: let id (T:*) (x:T) : T = x; The tra
- Page 96 and 97: Figure 3: Regular Expressions and N
- Page 98 and 99: Figure 5: Evaluation Rules Evaluati
- Page 100 and 101: 5. Exact Substitution: E, (x = v :
- Page 104 and 105: for most type variables, and that m
- Page 106 and 107: 2. miniKanren Overview This section
- Page 108 and 109: 3. Pseudo-Variadic Relations Just a
- Page 110 and 111: Replacing run 10 with run ∗ cause
- Page 112 and 113: As might be expected, we could use
- Page 114 and 115: Of course there are still infinitel
- Page 116 and 117: To ensure that streams produced by
- Page 118 and 119: 118 Scheme and Functional Programmi
- Page 120 and 121: On the other hand, we can use a hig
- Page 122 and 123: (ev* (Q (lambda (x) (+ x 1)))) # >
- Page 124 and 125: (term ’lam (lambda (x) (if (equal
- Page 126 and 127: a message: there is no guarantee th
- Page 128 and 129: (! (self) 3) (?) =⇒ 1 (?? odd?) =
- Page 130 and 131: (define new-server (spawn (lambda (
- Page 132 and 133: The abstraction shown in this secti
- Page 134 and 135: Erlang Termite List length (µs) (
- Page 136 and 137: 136 Scheme and Functional Programmi
- Page 138 and 139: page of j contains the URL of the p
- Page 140 and 141: 4. Solution The failed attempts abo
- Page 142 and 143: · ; · ; · :: Store × Frame Stac
- Page 144 and 145: logically creates a sub-session of
- Page 146 and 147: on this work, including Ryan Culpep
- Page 148 and 149: ing application operation. 1 As a r
- Page 150 and 151: such as image glyphs corresponding
- Page 152 and 153:
Phone For clarity, this code pr
- Page 154 and 155:
A. Porting TinyScheme to Qualcomm B
- Page 156 and 157:
156 Scheme and Functional Programmi
- Page 158 and 159:
ware installers have to install any
- Page 160 and 161:
defines a module named circle-lib i
- Page 162 and 163:
Figure 2. Sometimes special cases a
- Page 164 and 165:
Considering all of these issues tog