agda

“Strictly positive” in Agda

自作多情 提交于 2019-11-30 03:18:31
I'm trying to encode some denotational semantics into Agda based on a program I wrote in Haskell. data Value = FunVal (Value -> Value) | PriVal Int | ConVal Id [Value] | Error String In Agda, the direct translation would be; data Value : Set where FunVal : (Value -> Value) -> Value PriVal : ℕ -> Value ConVal : String -> List Value -> Value Error : String -> Value but I get an error relating to the FunVal because; Value is not strictly positive, because it occurs to the left of an arrow in the type of the constructor FunVal in the definition of Value. What does this mean? Can I encode this in

What is Axiom K?

旧时模样 提交于 2019-11-29 23:21:54
I've noticed the discussion of "Axiom K" comes up more often since HoTT. I believe it's related to pattern matching. I'm surprised that I cannot find a reference in TAPL, ATTAPL or PFPL. What is Axiom K? Is it used for ML-style pattern matching as in SML (or just dependent pattern matching)? What's an appropriate reference for Axiom K? Axiom K is also called the principle of uniqueness of identity proofs , and it is an axiom about the nature of the identity type in Martin-Löf's dependent type theory. This type doesn't exist (and in fact cannot be defined) in simpler type theories such as

Is it possible to derive induction for the church-encoded Nat?

余生长醉 提交于 2019-11-29 19:52:41
问题 I was just wondering if it is possible to derive induction for the church-encoded Nat type on Idris, Agda, Coq and similar. Notice this is a different issue from doing it on CoC (which is known to be impossible) because we have much more expressivity on those (we're able to, for example, extract the second element of Sigma). Here is a poor proof sketch on Idris (had a lot of syntax issues): CN : Type CN = (t : Type) -> t -> (t -> t) -> t CS : CN -> CN CS n t z s = s (n t z s) CZ : CN CZ t z s

Differences between Agda and Idris

☆樱花仙子☆ 提交于 2019-11-29 19:02:46
I'm starting to dive into dependently-typed programming and have found that the Agda and Idris languages are the closest to Haskell, so I started there. My question is: which are the main differences between them? Are the type systems equally expresive in both of them? It would be great to have a comprehensive comparative and a discussion about benefits. I've been able to spot some: Idris has type classes à la Haskell, whereas Agda goes with instance arguments Idris includes monadic and applicative notation Both of them seem to have some sort of rebindable syntax, although not really sure if

Termination-checking of function over a trie

限于喜欢 提交于 2019-11-29 14:52:12
I'm having difficulty convincing Agda to termination-check the function fmap below and similar functions defined recursively over the structure of a Trie . A Trie is a trie whose domain is a Type , an object-level type formed from unit, products and fixed points (I've omitted coproducts to keep the code minimal). The problem seems to relate to a type-level substitution I use in the definition of Trie . (The expression const (μₜ τ) * τ means apply the substitution const (μₜ τ) to the type τ .) module Temp where open import Data.Unit open import Category.Functor open import Function open import

Arity-generic programming in Agda

走远了吗. 提交于 2019-11-29 14:42:10
问题 How to write arity-generic functions in Agda? Is it possible to write fully dependent and universe polymorphic arity-generic functions? 回答1: I'll take an n-ary composition function as an example. The simplest version open import Data.Vec.N-ary comp : ∀ n {α β γ} {X : Set α} {Y : Set β} {Z : Set γ} -> (Y -> Z) -> N-ary n X Y -> N-ary n X Z comp 0 g y = {!!} comp (suc n) g f = {!!} Here is how N-ary is defined in the Data.Vec.N-ary module: N-ary : ∀ {ℓ₁ ℓ₂} (n : ℕ) → Set ℓ₁ → Set ℓ₂ → Set (N

How to define division operator in Agda?

亡梦爱人 提交于 2019-11-29 12:02:15
I want to divide two natural number. I have made function like this _/_ : N -> N -> frac m / one = m / one (suc m) / n = ?? I dont know what to write here. Please help. user3237465 As @gallais says you can use well-founded recursion explicitly, but I don't like this approach, because it's totally unreadable. This datatype record Is {α} {A : Set α} (x : A) : Set α where ¡ = x open Is ! : ∀ {α} {A : Set α} -> (x : A) -> Is x ! _ = _ allows to lift values to the type level, for example you can define a type-safe pred function: pred⁺ : ∀ {n} -> Is (suc n) -> ℕ pred⁺ = pred ∘ ¡ Then test-1 : pred⁺

Termination check on list merge

故事扮演 提交于 2019-11-29 10:43:29
Agda 2.3.2.1 can't see that the following function terminates: open import Data.Nat open import Data.List open import Relation.Nullary merge : List ℕ → List ℕ → List ℕ merge (x ∷ xs) (y ∷ ys) with x ≤? y ... | yes p = x ∷ merge xs (y ∷ ys) ... | _ = y ∷ merge (x ∷ xs) ys merge xs ys = xs ++ ys Agda wiki says that it's OK for the termination checker if the arguments on recursive calls decrease lexicographically. Based on that it seems that this function should also pass. So what am I missing here? Also, is it maybe OK in previous versions of Agda? I've seen similar code on the Internet and no

How to enumerate the elements of a list by `Fin`s in linear time?

左心房为你撑大大i 提交于 2019-11-29 07:54:45
We can enumerate the elements of a list like this: -- enumerate-ℕ = zip [0..] enumerate-ℕ : ∀ {α} {A : Set α} -> List A -> List (ℕ × A) enumerate-ℕ = go 0 where go : ∀ {α} {A : Set α} -> ℕ -> List A -> List (ℕ × A) go n [] = [] go n (x ∷ xs) = (n , x) ∷ go (ℕ.suc n) xs E.g. enumerate-ℕ (1 ∷ 3 ∷ 2 ∷ 5 ∷ []) is equal to (0 , 1) ∷ (1 , 3) ∷ (2 , 2) ∷ (3 , 5) ∷ [] . Assuming there is sharing in Agda, the function is linear. However if we try to enumerate the elements of a list by Fin s rather than ℕ s, the function becomes quadratic: enumerate-Fin : ∀ {α} {A : Set α} -> (xs : List A) -> List (Fin

Can you create functions that return functions of a dependent arity in a dependently typed language?

拜拜、爱过 提交于 2019-11-29 07:33:58
问题 From what I know about dependent types, I think that it should possible, but I've never seen an example of this before in a dependently typed language, so I'm not exactly sure where to start. What I want is a function of the form: f : [Int] -> (Int -> Bool) f : [Int] -> (Int -> Int -> Bool) f : [Int] -> (Int -> Int -> Int -> Bool) etc... This function takes a list of n Ints , and returns a predicate function of arity n that takes Ints as an argument. Is this sort of thing possible in a