total
: declare that a function is totalmutual
: for declaring mutually recursive types\x => x
\x : Int => x
|||
From here:
names which begin with a lower case letter are automatically bound as implicit arguments in types
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)
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
https://docs.idris-lang.org/en/latest/reference/repl.html
:?
: show help:import
/ :module
: import modules /
packages:t
: show type of a value:ti
: show type (including implicit arguments) of a
valueλΠ> :doc **
Used to build dependent pairs together with parentheses
$ rlwrap idris2 -p contrib
λΠ> :import Data.Telescope.Telescope
Imported module Data.Telescope.Telescope
Reload buffer | |̊ |
Case split | |̧ |
Book: Type driven development with Idirs
Category
An interface
Part of idris2 standard library
https://www.idris-lang.org/docs/idris2/0.6.0/contrib_docs/docs/Control.Category.html
(.)
: compose arrows
cat b c -> cat a b -> cat a c
(>>>)
: compose with arg order changed
('flow')
cat a b -> cat b c -> cat a c
Morphisms
record Morphism : Type -> Type -> Type
Mor : (a -> b) -> Morphism a b
Kleislimorphism
a -> b
Monad m => a -> m b
—
-- a -> m b a b
-- | | |
-- +------+-----+ +--+-+ +--+-+
-- | | | | | |
Kleislimorphism : (Type -> Type) -> Type -> Type -> Type
Kleisli : (a -> m b) -> Kleislimorphism a b
Contravariant
functorsinstance Contravariant : (Type -> Type) -> Type
-- Same as `(>$<)`
contramap : (a -> b) -> f b -> f a
(>$) :
contrib
package of idris2
λΠ> :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:
—
TypeIn : Telescope k -> Type
: A type with
dependencies in the context represented by the telescope