Content deleted Content added
Wikify →Features |
Merge sections |
||
Line 28:
The name ''Idris'' goes back to the character of the singing dragon in the 70's UK kids' program [[Ivor the Engine#Idris the Dragon|Ivor the Engine]].<ref>http://idris-lang.org/documentation/faq</ref>
==
Idris combines a number of features from relatively mainstream functional programming languages with features borrowed from proof assistants, in effect blurring the boundary between the two kinds of software.▼
===Functional programming===
The Syntax of Idris shows many similarities with that of Haskell. A [[hello world program]] in Idris might look like this:
Line 38 ⟶ 42:
</source>
The only differences between this program and its [[Haskell (programming language)#Code examples|Haskell equivalent]] are the single colon (instead of two) in the [[Type signature|signature]] of the main function and the omission of the word "where" in the module declaration.
====Inductive and parametric data types====
Like most modern functional programming languages, Idris supports a notion of inductively-defined data type and parametric polymorphism. Such types can be defined both in traditional "Haskell98" syntax:
<source lang="haskell">
data Tree a = Node (Tree a) (Tree a) | Leaf
</source>
or in the more general [[GADT]] syntax:
<source lang="haskell">
data Tree : Type -> Type where
Node : Tree a -> Tree a -> Tree a
Leaf : a -> Tree a
</source>
====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 of statically known length, traditionally called 'vectors':
<source lang="haskell">
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:
<source lang="haskell">
Line 63 ⟶ 92:
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.
===Proof assistant features===
▲Idris combines a number of features from relatively mainstream functional programming languages with features borrowed from proof assistants, in effect blurring the boundary between the two kinds of software.
===Code generation===
==References==
|