agda

Difference between type parameters and indices?

感情迁移 提交于 2019-12-17 06:37:19
问题 I am new to dependent types and am confused about the difference between the two. It seems people usually say a type is parameterized by another type and indexed by some value . But isn't there no distinction between types and terms in a dependently typed language? Is the distinction between parameters and indices fundamental? Can you show me examples showing difference in their meanings in both programming and theorem proving? 回答1: When you see a family of types, you may wonder whether each

Agda type-safe cast / coercion

丶灬走出姿态 提交于 2019-12-13 18:43:14
问题 I found handy a function: coerce : ∀ {ℓ} {A B : Set ℓ} → A ≡ B → A → B coerce refl x = x when defining functions with indexed types. In situations where indexes are not definitionally equal i,e, one have to use lemma, to show the types match. zipVec : ∀ {a b n m } {A : Set a} {B : Set b} → Vec A n → Vec B m → Vec (A × B) (n ⊓ m) zipVec [] _ = [] zipVec {n = n} _ [] = coerce (cong (Vec _) (0≡n⊓0 n)) [] zipVec (x ∷ xs) (y ∷ ys) = (x , y) ∷ zipVec xs ys Note , yet this example is easy to rewrite

Is Well-Founded recursion safe?

两盒软妹~` 提交于 2019-12-12 20:23:55
问题 In the question about non-termination With clauses obscuring termination an answer suggests to recourse to <-wellFounded . I looked at the definition of <-wellFounded before, and it strikes me there is a --safe in OPTIONS . Is it meant to work without this option? That is, is using --safe some optimisation, or is it working around some fundamental problem? So in this case we just delegate the termination problem to a function marked as "safe"? 回答1: It is completely safe. --safe holds a module

Agda: Why am I unable to pattern match on refl?

拟墨画扇 提交于 2019-12-12 13:31:53
问题 I'm trying to prove things about divisibility on integers. First I tried to prove that divisibility is reflective. ∣-refl : ∀{n} → n ∣ n Because I defined divisibility based on subtraction... data _∣_ : ℤ → ℤ → Set where 0∣d : ∀{d} → zero ∣ d n-d∣d : ∀{n d} → (n - d) ∣ d → n ∣ d ...it seems easy if I use the fact that n-n=0 : ∣-refl {n} with n-n≡0 n ... | refl = n-d∣d 0∣d But Agda rejects to pattern match on refl. Even if there is no possible other normal form of n-n=0 n . I've proven this

Equality on dependent record types

喜欢而已 提交于 2019-12-12 11:20:40
问题 I've been bashing my head against this problem for a while: I have record types, with dependent fields, and I want to prove equalities on record transformations. I've tried to distill the crux of my problem into a small example. Consider the following record type Rec , which has dependency between the fields: module Bar where open import Data.Nat open import Relation.Binary.PropositionalEquality as PE open import Relation.Binary.HeterogeneousEquality as HE record Rec : Set where field val : ℕ

Agda's standard library Data.AVL.Sets containing Data.String as values

寵の児 提交于 2019-12-12 10:48:11
问题 I am trying to figure out how to use Agda's standard library implementation of finite sets based on AVL trees in the Data.AVL.Sets module. I was able to do so successfully using ℕ as the values with the following code. import Data.AVL.Sets open import Data.Nat.Properties as ℕ open import Relation.Binary using (module StrictTotalOrder) open Data.AVL.Sets (StrictTotalOrder.isStrictTotalOrder ℕ.strictTotalOrder) test = singleton 5 Now I want to achieve the same thing but with Data.String as the

Stuck on a simple equality proof

蓝咒 提交于 2019-12-12 03:47:58
问题 I'm trying to implement some matrix operations and proofs around them in Agda. The code involve the something near the following definitions: open import Algebra open import Data.Nat hiding (_+_ ; _*_) open import Data.Vec open import Relation.Binary.PropositionalEquality module Teste {l l'}(cr : CommutativeSemiring l l') where open CommutativeSemiring cr hiding (refl) _×_ : ℕ → ℕ → Set l n × m = Vec (Vec Carrier m) n null : {n m : ℕ} → n × m null = replicate (replicate 0#) infixl 7 _∔_ _∔_ :

Agda: type isn't simplified in `with` block

断了今生、忘了曾经 提交于 2019-12-12 03:37:35
问题 I'm trying to solve the bonus exercise on page 23 of this tutorial, but I can't fill in this hole: lem-all-filter : {A : Set}(xs : List A)(p : A -> Bool) -> All (satisfies p) (filter p xs) lem-all-filter [] p = all[] lem-all-filter (x :: xs) p with p x ... | true = {! !} :all: lem-all-filter xs p ... | false = lem-all-filter xs p If I type C-c C-, in the hole then I get this message: Goal: isTrue (p x) -------------------------------- xs : List .A p : .A -> Bool x : .A .A : Set but I would

How to import the `∃-syntax`?

风流意气都作罢 提交于 2019-12-11 15:18:24
问题 open import Data.Product using (_×_; ∃; ∃-syntax) open import Data.List Any-∃ : ∀ {A : Set} {P : A → Set} {xs : List A} → ∃[ x ∈ xs ] P x Could not parse the application ∃[ x ∈ xs ] P x Operators used in the grammar: ∃[_] (prefix notation, level 20) [∃-syntax (C:\Users\Marko\AppData\Roaming\cabal\x86_64-windows-ghc-8.6.5\Agda-2.6.0\lib\agda-stdlib\src\Data\Product.agda:78,1-9)] when scope checking ∃[ x ∈ xs ] P x For some reason it seems like it is not importing the precedence properly from

Modeling System F's parametric polymorphism at Set₀

三世轮回 提交于 2019-12-11 12:13:29
问题 In System F, the kind of a polymorphic type is * (as that's the only kind in System F anyway...), so e.g. for the following closed type: [] ⊢ (forall α : *. α → α) : * I would like to represent System F in Agda, and because everything is in * , I thought I'd interpret types (like the above) as Agda Set s; so something like evalTy : RepresentationOfAWellKindedClosedType → Set However, Agda doesn't have polymorphic types, so the above type, in Agda, would need to be a (large!) Π type: idType =