Английская Википедия:Epigram (programming language)

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description Шаблон:Multiple issues Шаблон:Infobox programming language

Epigram is a functional programming language with dependent types, and the integrated development environment (IDE) usually packaged with the language. Epigram's type system is strong enough to express program specifications. The goal is to support a smooth transition from ordinary programming to integrated programs and proofs whose correctness can be checked and certified by the compiler. Epigram exploits the Curry–Howard correspondence, also termed the propositions as types principle, and is based on intuitionistic type theory.

The Epigram prototype was implemented by Conor McBride based on joint work with James McKinna. Its development is continued by the Epigram group in Nottingham, Durham, St Andrews, and Royal Holloway, University of London in the United Kingdom (UK). The current experimental implementation of the Epigram system is freely available together with a user manual, a tutorial and some background material. The system has been used under Linux, Windows, and macOS.

It is currently unmaintained, and version 2, which was intended to implement Observational Type Theory, was never officially released but exists in GitHub.

Syntax

Epigram uses a two-dimensional, natural deduction style syntax, with versions in LaTeX and ASCII. Here are some examples from The Epigram Tutorial:

Examples

The natural numbers

The following declaration defines the natural numbers: Шаблон:Sxhl The declaration says that Nat is a type with kind * (i.e., it is a simple type) and two constructors: zero and suc. The constructor suc takes a single Nat argument and returns a Nat. This is equivalent to the Haskell declaration "data Nat = Zero | Suc Nat".

In LaTeX, the code is displayed as:

<math>\underline{\mathrm{data}} \; \left(\frac{}{\mathsf{Nat} : \star}\right) \; \underline{\mathrm{where}} \;
       \left(\frac{}{\mathsf{zero} : \mathsf{Nat}}\right) \; ; \;
       \left(\frac{n : \mathsf{Nat}}{\mathsf{suc}\ n : \mathsf{Nat}}\right)</math>

The horizontal-line notation can be read as "assuming (what is on the top) is true, we can infer that (what is on the bottom) is true." For example, "assuming n is of type Nat, then suc n is of type Nat." If nothing is on the top, then the bottom statement is always true: "zero is of type Nat (in all cases)."

Recursion on naturals

<math>\mathsf{NatInd} : \begin{matrix}
       \forall P : \mathsf{Nat} \rightarrow \star \Rightarrow P\ \mathsf{zero} \rightarrow \\
       (\forall n : \mathsf{Nat} \Rightarrow P\ n \rightarrow P\ (\mathsf{suc}\ n)) \rightarrow\\
       \forall n : \mathsf{Nat} \Rightarrow P\ n
     \end{matrix}</math>
<math>\mathsf{NatInd}\ P\ mz\ ms\ \mathsf{zero} \equiv mz</math>
<math>\mathsf{NatInd}\ P\ mz\ ms\ (\mathsf{suc}\ n) \equiv ms\ n\ (NatInd\ P\ mz\ ms\ n)</math>

...And in ASCII: Шаблон:Sxhl

Addition

<math>\mathsf{plus}\ x\ y \Leftarrow \underline{\mathrm{rec}}\ x\ \{</math>
<math>\mathsf{plus}\ x\ y \Leftarrow \underline{\mathrm{case}}\ x\ \{</math>
<math>\mathsf{plus\ zero}\ y \Rightarrow y</math>
<math>\quad\quad \mathsf{plus}\ (\mathsf{suc}\ x)\ y \Rightarrow \mathsf{suc} (\mathsf{plus}\ x\ y)\ \}\ \}</math>

...And in ASCII: Шаблон:Sxhl

Dependent types

Epigram is essentially a typed lambda calculus with generalized algebraic data type extensions, except for two extensions. First, types are first-class entities, of type <math>\star</math>; types are arbitrary expressions of type <math>\star</math>, and type equivalence is defined in terms of the types' normal forms. Second, it has a dependent function type; instead of <math>P \rightarrow Q</math>, <math>\forall x : P \Rightarrow Q</math>, where <math>x</math> is bound in <math>Q</math> to the value that the function's argument (of type <math>P</math>) eventually takes.

Full dependent types, as implemented in Epigram, are a powerful abstraction. (Unlike in Dependent ML, the value(s) depended upon may be of any valid type.) A sample of the new formal specification capabilities dependent types bring may be found in The Epigram Tutorial.

See also

  • ALF, a proof assistant among the predecessors of Epigram.

Further reading

References

Шаблон:Reflist

External links