idris

In Idris, can I prove free theorems, e.g. the only (total) function of type `forall t. t -> t` is `id`?

和自甴很熟 提交于 2019-12-12 10:30:05
问题 For sufficiently polymorphic types, parametricity can uniquely determine the function itself (see Wadler's Theorems for free! for details). For example, the only total function with type forall t. t -> t is the identity function id . Is it possible to state and prove this in Idris? (And if it can't be proven inside Idris, is it true anyway?) The following is my attempt (I know that function equality is not a primitive concept in Idris, so I assert that any function of generic type t -> t

Define Equality of Lists Function

人走茶凉 提交于 2019-12-12 04:07:29
问题 Type-Driven Development with Idris presents this exercise: same_cons : {xs : List a} -> {ys : List a} -> xs = ys -> x :: xs = x :: ys However, I attempted to implement it via: data EqList : (xs : List a) -> (ys : List a) -> Type where Same : (xs: List a) -> EqList xs xs sameS : (xs : List a) -> (ys : List a) -> (x: a) -> (eq : EqList xs ys) -> EqList (x :: xs) (x :: ys) sameS xs xs x (Same xs) = Same (x :: xs) same_cons : {xs : List a} -> {ys : List a} -> (eq : EqList xs ys) -> EqList (x ::

How to put things with different type into a list, tagged by string?

巧了我就是萌 提交于 2019-12-11 19:29:14
问题 I'm trying to put things with different type into a list, tagged by string. What I want is something like that: arr1 : ?what_should_that_be arr1 = [("num" ** 1), ("str" ** "hello")] So I tried to prove that what I given as a tag is actually a valid tag (by providing a proof of IsTag tag ), but it seems that the compiler didn't get it, so what should I do now? data IsTag : String -> Type where NumIsTag : IsTag "num" StrIsTag : IsTag "str" total typeOf : (tag : String) -> {auto prf: IsTag tag}

Determine if Sum of Vect n Nat's Evenly Divides 5?

爷,独闯天下 提交于 2019-12-11 13:06:48
问题 Cactus demonstrated how to address my question: Helper Function to Determine if Nat `mod` 5 == 0. He wrote: onlyModBy5 : (n : Nat) -> {auto prf : n `modNat` 5 = 0} -> Nat onlyModBy5 n = n Then, I attempted to use that function to apply onlyModBy5 to the sum of a Vect n Nat 's. foo : (n : Nat) -> Vect n Nat -> Nat foo n xs = onlyModBy5 $ sum xs But I got this compile-time error: When checking right hand side of foo with expected type Nat When checking argument prf to function Main.onlyModBy5:

Trying to bring implicit argument into scope on the left side of a definition in Idris results in “is f applied to too many arguments” error

家住魔仙堡 提交于 2019-12-11 10:12:13
问题 The function applyRule is supposed to extract the implicit argument n that is used in another arguments it gets, of type VVect . data IVect : Vect n ix -> (ix -> Type) -> Type where -- n is here Nil : IVect Nil b (::) : b i -> IVect is b -> IVect (i :: is) b VVect : Vect n Nat -> Type -> Type -- also here VVect is a = IVect is (flip Vect a) -- just for completeness data Expression = Sigma Nat Expression applyRule : (signals : VVect is Double) -> (params : List Double) -> (sigmas : List Double

How to map over a Pair/Tuple?

与世无争的帅哥 提交于 2019-12-11 02:57:20
问题 In Haskell I would do join (***) . In Idris flatten (***) does not work ( (***) is complicated). 回答1: In Idris, there's no Functor / Applicative / Monad instances for r -> _ and no Arrow instance for -> , only via Morphism, so using flatten to do \f x -> f x x leads to horribly verbose code full of going from/to Morphism . You can do it, of course, I'm just not sure it's worth it... compare this: import Control.Arrow import Data.Morphisms both : (a -> b) -> (a, a) -> (b, b) both = applyMor .

Proving if n = m and m = o, then n + m = m + o in Idris?

吃可爱长大的小学妹 提交于 2019-12-11 02:23:32
问题 I am trying to improve my Idris skill by looking at some of the exercises Software Foundations (originally for Coq, but I am hoping the translation to Idris not too bad). I am having trouble with the "Exercise: 1 star (plus_id_exercise)" which reads: Remove "Admitted." and fill in the proof. Theorem plus_id_exercise : ∀ n m o : nat, n = m → m = o → n + m = m + o. Proof. (* FILL IN HERE *) Admitted. I have translated to the following problem in Idris: plusIdExercise : (n : Nat) -> (m : Nat) ->

Why rewrite does not change type of expression in this case?

瘦欲@ 提交于 2019-12-11 01:18:02
问题 In (*1) one can read next rewrite prf in expr If we have prf : x = y , and the required type for expr is some property of x , the rewrite ... in syntax will search for x in the required type of expr and replace it with y . Now, I have next piece of code (you can copy it to editor and try ctrl-l) module Test plusCommZ : y = plus y 0 plusCommZ {y = Z} = Refl plusCommZ {y = (S k)} = cong $ plusCommZ {y = k} plusCommS : S (plus y k) = plus y (S k) plusCommS {y = Z} = Refl plusCommS {y = (S j)} {k

using rewrite in Refl

感情迁移 提交于 2019-12-11 00:49:46
问题 I am working through Chapter 8 Type Driven Development with Idris, and I have a question about how rewrite interacts with Refl. This code is shown as an example of how rewrite works on an expression: myReverse : Vect n elem -> Vect n elem myReverse [] = [] myReverse {n = S k} (x :: xs) = let result = myReverse xs ++ [x] in rewrite plusCommutative 1 k in result where plusCommutative 1 k will look for any instances of 1 + k and replace it with k + 1 . My question is with this solution to

Idris: How do I call Idris function from Vala/C and return a string back to C/Vala

≯℡__Kan透↙ 提交于 2019-12-11 00:15:32
问题 I have this toy project: For the UI I use Vala code that is compiled to C. So I can display a message in UI that comes from Idris. Both on Idris ans Vala/C side I have this method that sets the pointer to the Idris function. So in Vala code you can see: global::afni = fn; that sets a global variable with a pointer to Idris the function. Later in another Vala method I call: int res = global::afni(0); string da_label = @"blah $res"; Gtk.Label label = new Gtk.Label (da_label); So I call comFn