fbpx
Wikipedia

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.

Idris
ParadigmFunctional
Designed byEdwin Brady
First appeared2007; 16 years ago (2007)[1]
Stable release
1.3.4[2] / October 22, 2021; 14 months ago (2021-10-22)
Preview release
0.6.0 (Idris 2)[3] / October 28, 2022; 2 months ago (2022-10-28)
OSCross-platform
LicenseBSD
Filename extensions.idr, .lidr
Websiteidris-lang.org
Influenced by
Agda, Clean,[4] Coq,[5] Epigram, F#, Haskell,[5] ML,[5] Rust[4]

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 JVM, CIL, and LLVM.[7]

Idris is named after a singing dragon from the 1970s UK children's television program Ivor the Engine.[8]

Features

Idris combines a number of features from relatively mainstream functional programming languages with features borrowed from proof assistants.

Functional programming

The 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 "where" in the module declaration.[9]

Inductive and parametric data types

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

data Tree a = Node (Tree a) (Tree a) | Leaf a 

or in the more general GADT-like syntax:

data Tree : Type -> Type where  Node : Tree a -> Tree a -> Tree a  Leaf : a -> Tree a 

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

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 

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.

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.[vague]

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.[10][11]

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

Idris 2

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.[12]

See also

References

  1. ^ Brady, Edwin (12 December 2007). . University of St Andrews School of Computer Science. Archived from the original on 2008-03-20.
  2. ^ "Release 1.3.4". Retrieved 2022-12-31.
  3. ^ "Idris 2 version 0.6.0 Released". www.idris-lang.org. Retrieved 2022-12-31.
  4. ^ a b "Uniqueness Types". Idris 1.3.1 Documentation. Retrieved 2019-09-26.
  5. ^ a b c "Idris, a language with dependent types". Retrieved 2014-10-26.
  6. ^ "Elaborator Reflection — Idris 1.3.2 documentation". Retrieved 27 April 2020.
  7. ^ "Code Generation Targets — Idris Latest documentation". docs.idris-lang.org.
  8. ^ "Frequently Asked Questions". Retrieved 2015-07-19.
  9. ^ "Syntax Guide — Idris 1.3.2 documentation". Retrieved 27 April 2020.
  10. ^ "Erasure By Usage Analysis — Idris latest documentation". idris.readthedocs.org.
  11. ^ "Benchmark results". ziman.functor.sk.
  12. ^ "idris-lang/Idris2". GitHub. Retrieved 2021-04-11.

External links

  • The Idris homepage, including documentation, frequently asked questions and examples
  • Idris at the Hackage repository
  • Documentation for the Idris Language (tutorial, language reference, etc.)

idris, programming, language, this, article, relies, excessively, references, primary, sources, please, improve, this, article, adding, secondary, tertiary, sources, find, sources, idris, programming, language, news, newspapers, books, scholar, jstor, august, . This article relies excessively on references to primary sources Please improve this article by adding secondary or tertiary sources Find sources Idris programming language news newspapers books scholar JSTOR August 2019 Learn how and when to remove this template message 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 IdrisParadigmFunctionalDesigned byEdwin BradyFirst appeared2007 16 years ago 2007 1 Stable release1 3 4 2 October 22 2021 14 months ago 2021 10 22 Preview release0 6 0 Idris 2 3 October 28 2022 2 months ago 2022 10 28 OSCross platformLicenseBSDFilename extensions idr lidrWebsiteidris lang wbr orgInfluenced byAgda Clean 4 Coq 5 Epigram F Haskell 5 ML 5 Rust 4 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 JVM CIL and LLVM 7 Idris is named after a singing dragon from the 1970s UK children s television program Ivor the Engine 8 Contents 1 Features 1 1 Functional programming 1 2 Inductive and parametric data types 1 3 Dependent types 1 4 Proof assistant features 1 5 Code generation 2 Idris 2 3 See also 4 References 5 External linksFeatures EditIdris combines a number of features from relatively mainstream functional programming languages with features borrowed from proof assistants Functional programming Edit The 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 where in the module declaration 9 Inductive and parametric data types Edit Idris supports inductively defined data types and parametric polymorphism Such types can be defined both in traditional Haskell98 like syntax data Tree a Node Tree a Tree a Leaf a or in the more general GADT like syntax data Tree Type gt Type where Node Tree a gt Tree a gt Tree a Leaf a gt Tree a Dependent types Edit 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 data Vect Nat gt Type gt Type where Nil Vect 0 a x a gt xs Vect n a gt Vect n 1 a This type can be used as follows total append Vect n a gt Vect m a gt Vect n m a append Nil ys ys append x xs ys x append xs ys 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 total pairAdd Num a gt Vect n a gt Vect n a gt Vect n a pairAdd Nil Nil Nil pairAdd x xs y ys x y pairAdd xs ys 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 Proof assistant features Edit 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 vague Code generation Edit Because Idris contains a proof assistant Idris programs can be written to pass proofs around If treated naively 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 2 EditIdris 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 also EditList of proof assistants Total functional programmingReferences Edit Brady Edwin 12 December 2007 Index of eb darcs Idris University of St Andrews School of Computer Science Archived from the original on 2008 03 20 Release 1 3 4 Retrieved 2022 12 31 Idris 2 version 0 6 0 Released www idris lang org Retrieved 2022 12 31 a b Uniqueness Types Idris 1 3 1 Documentation Retrieved 2019 09 26 a b c Idris a language with dependent types Retrieved 2014 10 26 Elaborator Reflection Idris 1 3 2 documentation Retrieved 27 April 2020 Code Generation Targets Idris Latest documentation docs idris lang org Frequently Asked Questions Retrieved 2015 07 19 Syntax Guide Idris 1 3 2 documentation Retrieved 27 April 2020 Erasure By Usage Analysis Idris latest documentation idris readthedocs org Benchmark results ziman functor sk idris lang Idris2 GitHub Retrieved 2021 04 11 External links EditThe Idris homepage including documentation frequently asked questions and examples Idris at the Hackage repository Documentation for the Idris Language tutorial language reference etc Retrieved from https en wikipedia org w index php title Idris programming language amp oldid 1130602574, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.