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
0
votes
0 answers

Stream type with monadic effects

Is there a standard type (especially in the stdlib) for a Stream type (by which I mean a potentially infinite, lazy sequence) which allows for effects when accessing the next element? Something like this pseudocode (for monad m, element type a) m…
joel
  • 6,359
  • 2
  • 30
  • 55
0
votes
0 answers

Why isn't this variable unknown in the type definition?

import Data.Vect data NamedVect : Type -> (names : Vect n String) -> Type where Nil : NamedVect a [] (::) : a -> NamedVect a ss -> NamedVect a (foo :: ss) aa : NamedVect Nat ["name", "age"] aa = [1,3] I'm interested in the foo variable. Where…
Gqqnbig
  • 5,845
  • 10
  • 45
  • 86
0
votes
1 answer

What are the builddir and outputdir and why are they generating a "File Not Found" error?

The Goal: package an executable "Hello, world" program in Idris2 I'm working from the docs, which gives descriptions of the package fields but sadly doesn't provide any examples. The issue: "File Not Found" compilation errors on the builddir and…
Eleanor Holley
  • 691
  • 1
  • 7
  • 27
0
votes
0 answers

Prove that `integerToFin` is just

I have the following setup: data Shape : ( n : Nat ) -> Type where Nil : Shape Z (::) : ( k : Nat ) -> { auto prf : IsSucc k } -> ( xs : Shape n ) -> Shape ( S n ) record Tensor ( n : Nat ) ( a : Type ) where constructor MkTensor …
Andrew
  • 311
  • 1
  • 7
0
votes
0 answers

How can I create a value of type Fin (divCeilNZ n m p)?

I'm experimenting with Idris and I had the idea to create a type that represented a valid reference to a subdivision of an array. So for example, if the array has a size of 100 and I want my subdivisions to be of size 20, the type would ensure that…
Bryan
  • 193
  • 7
0
votes
1 answer

How does Fin "know" not to go past its type bound?

How does Fin actually work? data Nat = Z | S Nat data Fin : (n : Nat) -> Type where FZ : Fin (S k) FS : Fin k -> Fin (S k) Where does k come from? Why isn't FZ always the value of (n: Nat) + 1? How does Fin "know" not to exceed its type…
0
votes
1 answer

How do I read all of standard input in Idris2?

I'm trying to figure out how to do something very simple: read all of standard input into a string (or a list of strings would be fine too). Prelude has getLine : HasIO io => io String, which can give me one line, but it doesn't give me a way to…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
0
votes
1 answer

Check length of a tuple by pattern matching

I want to learn idris by writing a length function that checks the length of a tuple. I leanred a tuple is made by the MkPair constructor so I try to do pattern matching. length : {t2:_} -> Pair t1 t2 -> Nat length (MkPair a b) = case b of …
Gqqnbig
  • 5,845
  • 10
  • 45
  • 86
0
votes
1 answer

How many times does a type function run, can you prove?

People say a dependent type language is slow in type checking so I think it is slow in running type functions. Use the classic example on https://idris2.readthedocs.io/en/latest/tutorial/typesfuns.html isSingleton : Bool -> Type isSingleton True =…
Gqqnbig
  • 5,845
  • 10
  • 45
  • 86
0
votes
1 answer

Can I print something in the middle of a function?

One example code on https://idris2.readthedocs.io/en/latest/tutorial/typesfuns.html says isSingleton returns Nat when the parameter is True, and returns a list when the parameter is False. isSingleton : Bool -> Type isSingleton True =…
Gqqnbig
  • 5,845
  • 10
  • 45
  • 86
0
votes
0 answers

Is this a bug in Idris's type-checker (or unification)?

The following snippet compiles fine in Idris 2, divMod2 : Nat -> (Nat, Bool) divMod2 Z = (Z, False) divMod2 (S Z) = (Z, True) divMod2 (S (S n)) = case divMod2 n of (k, r) => (S k, r) lm : {q:_} -> divMod2 (q+q) = (q, False) lm {q=0} = Refl lm {q=S…
0
votes
1 answer

Why does `clockTime` not seem to work for benchmarking, in Idris?

There are probably libraries to do this (although I haven't found any), I'm actually looking to measure the time a function takes to run in Idris. The way I've found is by using clockTime from System and differentiating between before and after a…
Foxy
  • 980
  • 8
  • 17
0
votes
1 answer

Idris2: Nested WITH clause

My Code My piece of code, i.e.: equal_suffix: Eq a => List a -> List a -> List a equal_suffix u v with (snocList u) equal_suffix _ _ | Empty = [] equal_suffix _ v | (Snoc x xs snx) with (snocList v) equal_suffix _ _ | (Snoc x xs snx)…
Clément Dato
  • 283
  • 2
  • 7
0
votes
1 answer

Returning a dependent pair from a foreign function

I have the following Chez support file: (define list-copy-with-length (xs) (cons (length xs) (list-copy xs))) and I have this Idris file: %foreign "scheme,chez:list-copy-with-length" prim__listToVect : List t -> (Nat, Vect n t) listToVect : List…
shadowtalker
  • 12,529
  • 3
  • 53
  • 96
0
votes
1 answer

Applying known proofs in Idris 1 interactive elaborator

I am trying to get some familiarity with theorem proving in Idris1 by exercise and am running into trouble. Suppose I have the following definition for naturals and the following theorems that I want to prove: data Natural = Z | S Natural plus :…
Andrii Kozytskyi
  • 123
  • 2
  • 11