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
5
votes
2 answers

In Idris, how to write a "vect generator" function that take a function of index in parameter

I'm trying to write in Idris a function that create a Vect by passing the size of the Vect and a function taking the index in parameter. So far, I've this : import Data.Fin import Data.Vect generate: (n:Nat) -> (Nat -> a) ->Vect n a generate n f =…
Molochdaa
  • 2,158
  • 1
  • 17
  • 23
5
votes
1 answer

natToFin when there is evidence that the conversion will work

The natToFin function from the standard library has the following signature: natToFin : Nat -> (n : Nat) -> Maybe (Fin n) natToFin 4 5 returns Just (FS (FS (FS (FS FZ)))) : Maybe (Fin 5), while natToFin 5 5 returns Nothing. I would like a…
mushroom
  • 6,201
  • 5
  • 36
  • 63
5
votes
1 answer

Force one argument to be greater than another in Idris

I am trying to write a function mSmallest that takes two natural numbers, n and m as inputs and produces a vector. The output vector contains the m smallest members of the finite set with n members. For example mSmallest 5 3 is supposed to produce…
mushroom
  • 6,201
  • 5
  • 36
  • 63
5
votes
2 answers

Example of a `Type 1` that is neither `Type` nor an inhabitant of `Type`

What is an example of an inhabitant of Type 1 that is neither Type nor an inhabitant of Type? I wasn't able to come up with anything while exploring in the Idris REPL. To be more precise, I'm looking for some x other than Type that yields the…
Snowball
  • 11,102
  • 3
  • 34
  • 51
5
votes
1 answer

Using heterogenous equality with =

What I have so far is: module Foo postulate P : 'P postulate NP : 'NP complexityProof : P = NP complexityProof = ?complexityProof_rhs But on trying to load the file, I just get: When elaborating type of Foo.complexityProof: When elaborating…
pdxleif
  • 1,750
  • 16
  • 15
5
votes
1 answer

idris-mode – Buffer has no process

I'm new to emacs (coming from vim, where I can't get idris-vim to work) and have these packages installed via el-get: ace-jump-mode installed A quick cursor location minor mode for emacs. el-get installed Manage the external…
mudri
  • 758
  • 3
  • 16
5
votes
1 answer

Partition a vector in Idris: why can't 0 and m+n be unified?

I would like to partition a vector in two new vectors. We cannot know what the length of the individual vectors will be, but the sum of the resulting vectors must be equal to the argument. I tried to capture this property as following: partition :…
Maarten Faddegon
  • 775
  • 5
  • 11
5
votes
1 answer

Idris Nat literals in types

I'd like Idris to prove that testMult : mult 3 3 = 9 is inhabited. Unfortunately this is typed as mult (fromInteger 3) (fromInteger 3) = fromInteger 9 : Type I can work around it like this: n3 : Nat; n3 = 3 n9 : Nat; n9 = 9 testMult : mult n3 n3 =…
huynhjl
  • 41,520
  • 14
  • 105
  • 158
4
votes
4 answers

Mapping functions over data in 'sum-types' in strongly typed programming languages

Today I encountered an implementation challenge with a large DU (sum-type) in F#, where I basically wanted to be able to map a set of functions over the values of the DU without having to repeat the matched case on the right hand side. The…
Michelrandahl
  • 3,365
  • 2
  • 26
  • 41
4
votes
1 answer

Can I avoid lower-case global variables being shadowed in types?

The following code compiles okay in Idris2: C : Nat C = 2 claim : C = 2 claim = Refl but it fails if C is not capitalized: c : Nat c = 2 claim : c = 2 claim = Refl The error message is Warning: We are about to implicitly bind the following…
4
votes
1 answer

The difference between dependent type signatures and proofs

With dependent types, you can either capture function properties in the type signature, like in concatenation with length-indexed lists (++) : Vect m a -> Vect n a -> Vect (m + n) a or you can not use dependent types in your signature, like…
joel
  • 6,359
  • 2
  • 30
  • 55
4
votes
1 answer

Why does function composition work when applied to functions that take multiple arguments?

I think I understand how function application works when writing out the steps, but the type signature arithmetic doesn't add up in my head. Apologies for the long prelude (no pun intended). To bring a specific example, this one is a slightly…
toraritte
  • 6,300
  • 3
  • 46
  • 67
4
votes
1 answer

How does Idris know where to insert Force and Delay?

According to the Idris crash course: The Idris type checker knows about the Lazy type, and inserts conversions where necessary between Lazy a and a, and vice versa. For example, b1 && b2 is converted into b1 && Delay b2. What are the specific…
4
votes
0 answers

What's the difference between Dependent Haskell and Idris

There is a big effort mainly from Richard Eisenberg and others to create a dependent typed Haskell. I have seen Haskell and now I am trying to learn Idris. I have seen that many things that Haskell tries to implement with dependent types,type…
Dragno
  • 3,027
  • 1
  • 27
  • 41
4
votes
0 answers

How to garbage collect an Idris/C Struct?

I'd like Idris to garbage-collect my Idris Struct. The docs for Struct FFI say The field types of a Struct can be any of the following: ... Ptr a or AnyPtr (void* in C) Another Struct, which is a pointer to a struct in C and offer the following…
joel
  • 6,359
  • 2
  • 30
  • 55