Questions tagged [idris]

Idris is a general purpose pure functional programming language with dependent types.

Idris is a general-purpose purely functional programming language with dependent types, strict or optional lazy evaluation and features such as a totality checker.


Useful links:

785 questions
8
votes
4 answers

Where and Why should I use extra empty patterns?

For example: intersectBy : (a -> a -> Bool) -> List a -> List a -> List a intersectBy _ [] _ = [] intersectBy _ _ [] = [] intersectBy eq xs ys = [x | x <- xs, any (eq x) ys] There are extra patterns for [] and seems like they are…
cnd
  • 32,616
  • 62
  • 183
  • 313
8
votes
1 answer

Implementing Total Parsers in Idris Based on a Paper on Agda

I am trying to implement total parsers with Idris, based on this paper. First I tried to implement the more basic recogniser type P: Tok : Type Tok = Char mutual data P : Bool -> Type where fail : P False empty : P True sat : (Tok ->…
Vic Smith
  • 3,477
  • 1
  • 18
  • 29
8
votes
1 answer

Generating run time proofs with type predicates in Idris

I am using this type to reason about strings on which decidable parsing can be performed: data Every : (a -> Type) -> List a -> Type where Nil : {P : a -> Type} -> Every P [] (::) : {P : a -> Type} -> P x -> Every P xs -> Every P (x::xs) For…
Vic Smith
  • 3,477
  • 1
  • 18
  • 29
8
votes
2 answers

How to rewrite a function body in Idris so that the type corresponds to the function signature and the whole thing compiles

I would like for this to compile: foo: Vect n String -> Vect n String foo {n} xs = take n xs This fails to compile because the compiler cannot unify n with n + m. I understand that this is because of the signature of take for Vect's but I cannot…
jedesah
  • 2,983
  • 2
  • 17
  • 29
8
votes
2 answers

How can finite numbers work? (dependent types)

I'm interested in dependently typed languages. Finite numbers seem very usable to me. For example, to safely index fixed-size arrays. But the definition is not clear for me. The data type for finite numbers in Idris can be the following: (And…
Boldizsár Németh
  • 1,847
  • 13
  • 20
7
votes
1 answer

Why does Haskell 9.0 not have Zero in its linear types, but Idris 2 does?

From the Idris 2 publication about linear types "Idris 2: Quantitative Type Theory in Practice": For Idris 2, we make a concrete choice of semiring, where a multiplicity can be one of: 0: the variable is not used at run time 1: the variable is…
srghma
  • 4,770
  • 2
  • 38
  • 54
7
votes
1 answer

Does Idris have MaybeT?

Does Idris have MaybeT from Haskell or is there something else I should use instead? I am trying to do computations with many values of type IO (Maybe a). How can combine Maybe and IO into a single monad (like MaybeT IO in Haskell) in Idris?
michaelmesser
  • 3,601
  • 2
  • 19
  • 42
7
votes
1 answer

Runtime "type terms" in LiquidHaskell vs. Idris

I have been playing around with LiquidHaskell and Idris lately and i got a pretty specific question, that i could not find a definitive answer anywhere. Idris is a dependently typed language which is great for the most part. However i read that some…
Lazarus535
  • 1,158
  • 1
  • 8
  • 23
7
votes
1 answer

How to use `deriving` in Idris?

I'm trying to deriving Show, Eq, Ord etc in Idris, but none of the following trials works: trail #1: data Expr = Lit Int | Neg Expr | Add Expr Expr deriving (Show) got: deriving.idr:5:15-18: | 5 | deriving (Show) | …
luochen1990
  • 3,689
  • 1
  • 22
  • 37
7
votes
1 answer

Is there a type theory in which the equivalence of identically shaped inductive datatypes is representable?

Say I have two inductively defined datatypes: Inductive list1 (A : Type) : Type := | nil1 : list1 A | cons1 : A -> list1 A -> list1 A. and Inductive list2 (A : Type) : Type := | nil2 : list2 A | cons2 : A -> list2 A -> list2 A. For any P…
LogicChains
  • 4,332
  • 2
  • 18
  • 27
7
votes
3 answers

Is it possible to derive induction for the church-encoded Nat?

I was just wondering if it is possible to derive induction for the church-encoded Nat type on Idris, Agda, Coq and similar. Notice this is a different issue from doing it on CoC (which is known to be impossible) because we have much more…
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
7
votes
1 answer

Why are these two tuples in idris equal?

I am reading Type driven development with Idris, and one of the exercises asks the reader to define a type TupleVect, such that a vector can be represented as: TupleVect 2 ty = (ty, (ty, ())) I solved it by defining the following type: TupleVect :…
larlon
  • 557
  • 1
  • 6
  • 17
7
votes
0 answers

`zipWith (-) [6,5,4] [1,2,3]` errors

Why does zipWith (-) [6,5,4] [1,2,3] fail in Idris? Is it possible to avoid that error without writing a specialized zipWith function? main8.idr: module Main import Data.HVect import Data.Vect import Data.Vect.Quantifiers t : Vect 3 Nat t =…
michaelmesser
  • 3,601
  • 2
  • 19
  • 42
7
votes
1 answer

Understanding performance characteristics of Wadler's Prettier Printer

I am using the Prettier Printer implementation from the contrib library in Idris. When I fold with the |//| operator on a list of Docs, the performance quickly explodes, i.e. the following code doesn't terminate before I lose my…
Felix
  • 8,385
  • 10
  • 40
  • 59
7
votes
3 answers

Dependent types: Vector of vectors

I'm new to dependent types (I'm trying both Idris and Coq, despite their big differences). I'm trying to express the following type: given a type T and a sequence of k nats n1, n2, ... nk, a type consisting of k sequences of T with length n1, n2,…
lodo
  • 2,314
  • 19
  • 31