idris

Using heterogenous equality with =

早过忘川 提交于 2019-12-05 19:39:45
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 argument y to type constructor =: Can't unify 'NP with 'P Specifically: Can't unify "NP" with "P" A little suprised at the error, as I thought Idris, having heterogeneous "John Major" equality, was fine with differing types on the left and right-hand side of =. There's a different symbol for that, now? From the documentation: Note : Idris's equality type is

Is there a nice way to use `->` directly as a function in Idris?

好久不见. 提交于 2019-12-05 17:28:48
问题 One can return a type in a function in Idris, for example t : Type -> Type -> Type t a b = a -> b But the situation came up (when experimenting with writing some parsers) that I wanted to use -> to fold a list of types, ie typeFold : List Type -> Type typeFold = foldr1 (->) So that typeFold [String, Int] would give String -> Int : Type . This doesn't compile though: error: no implicit arguments allowed here, expected: ")", dependent type signature, expression, name typeFold = foldr1 (->) ^

Implementing vector addition in Coq

[亡魂溺海] 提交于 2019-12-05 15:03:27
Implementing vector addition in some of the dependently typed languages (such as Idris) is fairly straightforward. As per the example on Wikipedia : import Data.Vect %default total pairAdd : Num a => Vect n a -> Vect n a -> Vect n a pairAdd Nil Nil = Nil pairAdd (x :: xs) (y :: ys) = x + y :: pairAdd xs ys (Note how Idris' totality checker automatically infers that addition of Nil and non- Nil vectors is a logical impossibility.) I am trying to implement the equivalent functionality in Coq, using a custom vector implementation, albeit very similar to the one provided in the official Coq

natToFin when there is evidence that the conversion will work

一曲冷凌霜 提交于 2019-12-05 10:19:47
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 function with the following signature: myNatToFin : (m : Nat) -> (n : Nat) -> { auto p : n `GT` m } -> Fin n It behaves the same as the standard lib function but doesn't need to return a Maybe because it is always possible to generate a Fin n from m given that n is greater than m . How do I implement myNatToFin ? You can do it directly by recursing on m , n

Can Idris infer indices in types of top-level constants?

混江龙づ霸主 提交于 2019-12-05 06:41:48
For example, Agda allows me to write this: open import Data.Vec open import Data.Nat myVec : Vec ℕ _ myVec = 0 ∷ 1 ∷ 2 ∷ 3 ∷ [] and myVec will have type Vec ℕ 4 as expected. But if I try the same in Idris: import Data.Vect myVec : Vect _ Nat myVec = [0, 1, 2, 3] I get an error message from the typechecker: When checking right hand side of myVec with expected type Vect len Nat Type mismatch between Vect 4 Nat (Type of [0, 1, 2, 3]) and Vect len Nat (Expected type) Specifically: Type mismatch between 4 and len Is there a way to define myVec in Idris without manually specifying the index of the

(xs : Vect n elem) -> Vect (n * 2) elem

ⅰ亾dé卋堺 提交于 2019-12-05 01:06:00
问题 The book Type Driven Development with Idris presents this exercise: Define a possible method that fits the signature: two : (xs : Vect n elem) -> Vect (n * 2) elem I tried: two : (xs : Vect n elem) -> Vect (n * 2) elem two xs = xs ++ xs But I got the following error: *One> :r Type checking ./One.idr One.idr:9:5:When checking right hand side of two: Type mismatch between Vect (n + n) elem (Type of xs ++ xs) and Vect (mult n 2) elem (Expected type) Specifically: Type mismatch between plus n n

Idris eager evaluation

瘦欲@ 提交于 2019-12-04 22:17:06
In Haskell , I might implement if like this: if' True x y = x if' False x y = y spin 0 = () spin n = spin (n - 1) This behaves how I expect : haskell> if' True (spin 1000000) () -- takes a moment haskell> if' False (spin 1000000) () -- immediate In Racket , I could implement a flawed if like this: (define (if2 cond x y) (if cond x y)) (define (spin n) (if (= n 0) (void) (spin (- n 1)))) This behaves how I expect : racket> (if2 #t (spin 100000000) (void)) -- takes a moment racket> (if2 #f (spin 100000000) (void)) -- takes a moment In Idris , I might implement if like this: if' : Bool -> a -> a

I can't prove (n - 0) = n with Idris

大城市里の小女人 提交于 2019-12-04 16:33:11
问题 I am trying to prove, what to my mind is a reasonable theorem: theorem1 : (n : Nat) -> (m : Nat) -> (n + (m - n)) = m Proof by induction gets to the point where me need to prove this: lemma1 : (n : Nat) -> (n - 0) = n This is what happens when I try to prove it (the lemma, for simplicity sake) using the interactive prover: ---------- Goal: ---------- {hole0} : (n : Nat) -> minus n 0 = n > intros ---------- Other goals: ---------- {hole0} ---------- Assumptions: ---------- n : Nat ----------

Constraining a function argument in an interface

烂漫一生 提交于 2019-12-04 13:39:43
What is the syntax to constrain a function argument in an interface which takes a function? I tried: interface Num a => Color (f : a -> Type) where defs... But it says the Name a is not bound in interface... Cactus Your interface actually has two parameters: a and f . But f should be enough to pick an implementation : interface Num a => Color (a : Type) (f : a -> Type) | f where f here is called a determining parameter . Here's a nonsensical full example: import Data.Fin interface Num a => Color (a : Type) (f : a -> Type) | f where foo : (x : a) -> f (1 + x) Color Nat Fin where foo _ = FZ x :

How can I establish a bijection between a tree and its traversal?

元气小坏坏 提交于 2019-12-04 10:31:11
问题 I was looking at How does inorder+preorder construct unique binary tree? and thought it would be fun to write a formal proof of it in Idris. Unfortunately, I got stuck fairly early on, trying to prove that the ways to find an element in a tree correspond to the ways to find it in its inorder traversal (of course, I'll also need to do that for the preorder traversal). Any ideas would be welcome. I'm not particularly interested in a complete solution—more just help getting started in the right