Idris 2


General

Implicit arguments

From here:

names which begin with a lower case letter are automatically bound as implicit arguments in types

Dependent pairs

https://idris2.readthedocs.io/en/latest/tutorial/typesfuns.html#dependent-pairs

Eg: an implementation of Vector:

(n:Nat ** Vector n Int)

Another example??ˡ: (n : Nat) * (vars : Vect n String) * ScopedLC vars)

Multiplicty

Values:

Explicit multiplicity examples:

Default multiplicity values:

Fun fact: Following is a function that cannot be realized as it requires two instances of a but only 1 is allowed:

https://idris2.readthedocs.io/en/latest/tutorial/multiplicities.html

REPL

https://docs.idris-lang.org/en/latest/reference/repl.html

λΠ> :doc **
Used to build dependent pairs together with parentheses
$ rlwrap idris2 -p contrib

λΠ> :import Data.Telescope.Telescope
Imported module Data.Telescope.Telescope

vim plugin: idir

Reload buffer
Case split

Book: Type driven development with Idirs

Idris1 vs Idris2

Category

Morphisms

record Morphism : Type -> Type -> Type
  Mor : (a -> b) -> Morphism a b

Kleislimorphism

https://www.idris-lang.org/docs/idris2/0.6.0/base_docs/docs/Data.Morphisms.html#Data.Morphisms.Kleislimorphism

--                    a -> m b        a       b
--                       |            |       |  
--                +------+-----+   +--+-+  +--+-+
--                |            |   |    |  |    |
Kleislimorphism : (Type -> Type) -> Type -> Type -> Type

Contravariant functors

https://www.idris-lang.org/docs/idris2/0.6.0/base_docs/docs/Data.Contravariant.html#Data.Contravariant.Contravariant

instance Contravariant : (Type -> Type) -> Type
    -- Same as `(>$<)`
    contramap : (a -> b) -> f b -> f a
    (>$) : 

Telescope

λΠ> :t Telescope
Data.Telescope.Telescope.Left.Telescope : Nat -> Type
Data.Telescope.Telescope.Right.Telescope : Nat -> Type
Data.Telescope.Telescope.Tree.Telescope : Nat -> Type

-- Left-nested
-- New values are appended. ie, nesting happens on the left.
--
namespace Left
  data Telescope : Nat -> Type
    Nil : Telescope 0
    (-.) : (gamma : Telescope k) -> TypeIn gamma -> Telescope (S k)

--------------------

-- Right-nested
-- New values are prepended. ie, nesting happens on the right.
--
namespace Right
  data Telescope : Nat -> Type
    Nil : Telescope 0
    (.-) : (ty : Type) -> (ty -> Telescope k) -> Telescope (S k)

--------------------

-- Tree-shaped
--
namespace Tree
  data Telescope : Nat -> Type
    Nil : Telescope 0
    Elt : Type -> Telescope 1
    (++) : (gamma : Telescope m) -> (Environment gamma -> Telescope n) -> Telescope (m + n)

See:

Misc

Trivia