| Idris | |
|---|---|
| Paradigm | Functional |
| Designed by | Edwin Brady |
| First appeared | 2007 [1] |
| Stable release | Idris2 v0.8.0 [2] / October 31, 2025 |
| Typing discipline | Dependent |
| OS | Cross-platform |
| License | BSD |
| Filename extensions | .idr, .lidr |
| Website | www |
| Influenced by | |
| Agda, Clean, [3] Rocq (previously known as Coq), [4] Epigram, F#, Haskell, [4] ML, [4] Rust [3] | |
Idris is a purely-functional programming language with dependent types, quantity annotations, optional lazy evaluation, and features such as a totality checker. Idris is designed to be a general-purpose programming language similar to Haskell, but may also be used as a proof assistant.
The Idris type system is similar to Agda's. Compared to Agda, Idris prioritizes management of side effects and support for embedded domain-specific languages. Idris is compiled by modular backends, which provide code generation and a runtime system. [5] The Idris compiler includes backends for Chez Scheme, Racket, JavaScript (both browser- and Node.js-based), and C. Additional third-party backends are available for other platforms. [6]
Idris is named after a singing dragon from the 1970s UK children's television programme Ivor the Engine . [7]
Idris combines a number of features from relatively mainstream functional programming languages with features borrowed from proof assistants.
The syntax of Idris shows many similarities with that of Haskell. A hello world program in Idris might look like this:
moduleMainmain: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 "where" in the module declaration. [8]
Idris supports inductively-defined data types and parametric polymorphism. Such types can be defined both in traditional Haskell 98-like syntax:
dataTreea=Node(Treea)(Treea)|Leafa or in the more general generalized algebraic data type (GADT)-like syntax:
dataTree:Type->TypewhereNode:Treea->Treea->Treea Leaf:a->Treea With 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:
dataVect:Nat->Type->TypewhereNil:Vect0a (::):(x:a)->(xs:Vectna)->Vect(n+1)a This type can be used as follows:
totalappend:Vectna->Vectma->Vect(n+m)a appendNilys=ys append(x::xs)ys=x::appendxsys The function append appends a vector of m elements of type a to a vector of n elements of type a. Since the precise types of the input vectors depend on a value, it is possible to be certain at compile time that the resulting vector will have exactly (n + m) elements of type a. The word "total" invokes the totality checker which will report an error if the function doesn't cover all possible cases or cannot be (automatically) proven not to enter an infinite loop.
Another common example is pairwise addition of two vectors that are parameterized over their length:
totalpairAdd:Numa=>Vectna->Vectna->Vectna pairAddNilNil=Nil pairAdd(x::xs)(y::ys)=x+y::pairAddxsys Num a signifies that the type a belongs to the type class Num. Note that this function still typechecks successfully as total, even though there is no case matching Nil in one vector and a number in the other. Because the type system can prove that the vectors have the same length, we can be sure at compile time that case will not occur and there is no need to include that case in the function’s definition.
Dependent 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 (Rocq 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 Rocq.[ vague ]
Because 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. [9] [10]
By default, Idris generates native code through C. The other officially supported backend generates JavaScript.
Idris 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. [11]