Whiley (programming language)
Whiley is an experimental programming language that combines features from the functional and imperative programming paradigms, and supports formal specification through function preconditions, postconditions and loop invariants.[1] The language uses flow-sensitive typing also termed flow typing. The Whiley project began in 2009 in response to the "Verifying Compiler Grand Challenge" put forward by Tony Hoare in 2003.[2] The first public release of Whiley was in June, 2010.[3] Developed by David Pearce mainly, Whiley is an open source project with contributions from a small community. The system has been used for student research projects and in teaching undergraduate classes.[4] It was supported from 2012–2014 by the Royal Society of New Zealand's Marsden Fund.[5] The Whiley compiler generates code for the Java virtual machine (JVM) and can interoperate with Java and other JVM-based languages. OverviewThe goal of Whiley is to provide a realistic programming language where verification is used routinely and without thought. The idea of such a tool has a long history, but was strongly promoted in the early 2000s through Hoare's Verifying Compiler Grand Challenge. The purpose of this challenge was to spur new efforts to develop a verifying compiler, roughly described as follows:[6]
The main purpose of such a tool is to improve software quality by ensuring a program meets a formal specification. Whiley follows many attempts to develop such tools, including notable efforts such as SPARK/Ada, ESC/Java, Spec#, Dafny, Why3,[7] and Frama-C. Most previous attempts to develop a verifying compiler focused on extending existing programming languages with constructs for writing specifications. For example, ESC/Java and the Java Modeling Language add annotations to specify preconditions and postconditions to Java. Likewise, Spec# and Frama-C add similar constructs to the C# and C languages. However, these languages contain many features which pose difficult or insurmountable problems for verification.[8] In contrast, the Whiley language was designed from scratch in an effort to avoid common pitfalls and make verification more tractable.[9] FeaturesThe syntax of Whiley follows the general appearance of imperative or object-oriented programming languages. Indentation syntax (the off-side rule) is used instead of braces to delineate statement blocks, giving a strong resemblance to Python. However, the imperative look of Whiley can be somewhat misleading as the language core is functional and pure. Whiley distinguishes a Whiley takes an unusual approach to type checking termed flow typing. Variables can have different static types at different points in a function or method. Flow typing is similar to occurrence typing as found in Racket.[10] To aid flow typing, Whiley supports union, intersection and negation types.[11] Union types are comparable to sum types found in functional languages like Haskell but, in Whiley, they are not disjoint. Intersection and negation types are used in the context of flow typing to determine the type of a variable on the true and false branches of a runtime type test. For example, suppose a variable Whiley uses a structural rather than nominal type system. Modula-3, Go and Ceylon are examples of other languages which support structural typing in some form. Whiley supports reference lifetimes similar to those found in Rust. Lifetimes can be given when allocating new objects to indicate when they can be safely deallocated. References to such objects must then include lifetime identifier to prevent dangling references. Every method has an implicit lifetime referred to by Whiley has no built-in support for concurrency and no formal memory model to determine how reading/writing to shared mutable state should be interpreted. ExampleThe following example illustrates many of the interesting features in Whiley, including the use of postconditions, loop invariants, type invariants, union types and flow typing. The function is intended to return the first index of an integer // Define the type of natural numbers
type nat is (int x) where x >= 0
public function indexOf(int[] items, int item) -> (int|null index)
// If int returned, element at this position matches item
ensures index is int ==> items[index] == item
// If int returned, element at this position is first match
ensures index is int ==> no { i in 0 .. index | items[i] == item }
// If null returned, no element in items matches item
ensures index is null ==> no { i in 0 .. |items| | items[i] == item }:
//
nat i = 0
//
while i < |items|
// No element seen so far matches item
where no { j in 0 .. i | items[j] == item }:
//
if items[i] == item:
return i
i = i + 1
//
return null
In the above, the function's declared return type is given the union type The above example also illustrates the use of an inductive loop invariant. The loop invariant must be shown to hold on entry to the loop, for any given iteration of the loop and when the loop exits. In this case, the loop invariant states what is known about the elements of the The above example also defines the type HistoryWhiley began in 2009 with the first public release, Another important milestone in the evolution of Whiley came in version References
External links |
Portal di Ensiklopedia Dunia