ⓘ Idris (programming language)


ⓘ 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 it is designed to be a general-purpose programming language similar to Haskell.

The Idris type system is similar to Agda, and proofs are similar to Coq, including tactics. 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 Cheneys algorithm and JavaScript both browser- and Node.js-based. There are third-party code generators for other platforms, including JVM, CIL, and LLVM.

Idris 2, which has a Chez Scheme backend and uses quantitative type theory, is currently being worked on.

Idris is named after a singing dragon from the 1970s UK childrens television program Ivor the Engine.


1.1. Features Functional programming

The syntax of Idris shows many similarities with that of Haskell. A hello world program in Idris might look like this:

The only differences between this program and its Haskell equivalent are the single colon instead of two in the signature of the main function and the omission of the word "where" in the module declaration.


1.2. Features Inductive and parametric data types

Idris supports inductively-defined data types and parametric polymorphism. Such types can be defined both in traditional "Haskell98" syntax:

or in the more general GADT syntax:


1.3. Features Dependent types

With dependent types, it is possible for values to appear in the types; in effect, any value-level computation can be performed during typechecking. The following defines a type of lists whose lengths are known before the program runs, traditionally called vectors:

This type can be used as follows:

The functions append 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 doesnt 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:

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. Since both vectors are ensured by the type system to have exactly the same length, we can be sure at compile time that this case will not occur. Hence it does not need to be mentioned for the function to be total.


1.4. Features Proof assistant features

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 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.


1.5. Features Code generation

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.

By default, Idris generates native code through C. The other officially supported backend generates JavaScript.