Idris (programming language)
Idris is a purely-functional programming language with dependent types, optional lazy evaluation, and features such as a totality checker. Idris may be used as a proof assistant, but is designed to be a general-purpose programming language similar to Haskell. The Idris type system is similar to Agda's, and proofs are similar to Coq's, including tactics (theorem proving functions/procedures) via elaborator reflection.[6] Compared to Agda and Coq, Idris prioritizes management of side effects and support for embedded domain-specific languages. Idris compiles to C (relying on a custom copying garbage collector using Cheney's algorithm) and JavaScript (both browser- and Node.js-based). There are third-party code generators for other platforms, including Java virtual machine (JVM), Common Intermediate Language (CIL), and LLVM.[7] Idris is named after a singing dragon from the 1970s UK children's television program Ivor the Engine.[8] FeaturesIdris combines a number of features from relatively mainstream functional programming languages with features borrowed from proof assistants. Functional programmingThe syntax of Idris shows many similarities with that of Haskell. A hello world program in Idris might look like this: module Main
main : IO ()
main = putStrLn "Hello, World!"
The only differences between this program and its Haskell equivalent are the single (instead of double) colon in the type signature of the main function, and the omission of the word " Inductive and parametric data typesIdris supports inductively-defined data types and parametric polymorphism. Such types can be defined both in traditional Haskell 98-like syntax: data Tree a = Node (Tree a) (Tree a) | Leaf a
or in the more general generalized algebraic data type (GADT)-like syntax: data Tree : Type -> Type where
Node : Tree a -> Tree a -> Tree a
Leaf : a -> Tree a
Dependent typesWith dependent types, it is possible for values to appear in the types; in effect, any value-level computation can be performed during type checking. The following defines a type of lists whose lengths are known before the program runs, traditionally called vectors: data Vect : Nat -> Type -> Type where
Nil : Vect 0 a
(::) : (x : a) -> (xs : Vect n a) -> Vect (n + 1) a
This type can be used as follows: total
append : Vect n a -> Vect m a -> Vect (n + m) a
append Nil ys = ys
append (x :: xs) ys = x :: append xs ys
The function Another common example is pairwise addition of two vectors that are parameterized over their length: total
pairAdd : Num a => Vect n a -> Vect n a -> Vect n a
pairAdd Nil Nil = Nil
pairAdd (x :: xs) (y :: ys) = x + y :: pairAdd xs ys
Proof assistant featuresDependent types are powerful enough to encode most properties of programs, and an Idris program can prove invariants at compile time. This makes Idris into a proof assistant. There are two standard ways of interacting with proof assistants: by writing a series of tactic invocations (Coq style), or by interactively elaborating a proof term (Epigram–Agda style). Idris supports both modes of interaction, although the set of available tactics is not yet as useful as that of Coq.[vague] Code generationBecause Idris contains a proof assistant, Idris programs can be written to pass proofs around. If treated naïvely, such proofs remain around at runtime. Idris aims to avoid this pitfall by aggressively erasing unused terms.[10][11] By default, Idris generates native code through C. The other officially supported backend generates JavaScript. Idris 2Idris 2 is a new self-hosted version of the language which deeply integrates a linear type system, based on quantitative type theory. It currently compiles to Scheme and C.[12] See alsoReferences
External links
|
Portal di Ensiklopedia Dunia