agda

Type Hierarchy in Agda

不打扰是莪最后的温柔 提交于 2019-12-09 15:46:55
问题 I am trying to figure out how type hierarchies work in Agda. Assuming I define a set type X: X : Set and then proceed to constructing an inductive type data Y : X -> Set where What is the type of X -> Set ? Is it Set or Type? Thank you! 回答1: Well, why not ask Agda itself? I'm going to use excellent Agda mode for Emacs. We start with: module Hierarchy where postulate X : Set data Y : X → Set where -- empty We have to load the file using C-c C-l ; this typechecks the file, turns ? s into holes,

Use Agda's input method in other emacs mode?

纵饮孤独 提交于 2019-12-09 15:27:29
问题 How do I use Agda's input method to enter unicode characters in non-Agda mode? I don't see its name showing up when I try set-input-method . The reason I want to use Agda's input method instead of TeX is because there are characters I want that can't enter in TeX . Or, maybe an alternate question would be "How do I add more shortcuts to enter unicode characters in the existing TeX input method?" Thank you very much 回答1: Add the following commands in your .emacs file: ;; Using the input method

A definition for finite sets in Agda

随声附和 提交于 2019-12-09 14:30:42
问题 I am new to Agda. I'm reading the paper "Dependent Types at Work" by Ana Bove and Peter Dybjer. I don't understand the discussion of Finite Sets (on page 15 in my copy). The paper defines a Fin type: data Fin : Nat -> Set where fzero : {n : Nat} -> Fin (succ n) fsucc : {n : Nat} -> Fin n -> Fin (succ n) I must be missing something obvious. I don't understand how this definition works. Could someone simply translate the definition of Fin into everyday English? That might be all I need to

Do agda programs necessarily terminate?

笑着哭i 提交于 2019-12-09 00:45:55
问题 It has been stated a few places that all agda programs terminate. However I can construct a function like this: stall : ∀ n → ℕ stall 0 = 0 stall x = stall x The syntax highlighter doesn't seem to like it, but there are no compilation errors. Computing the normal form of stall 0 results in 0 . Computing the result of stall 1 causes Emacs to hang in what looks a lot like a non-terminating loop. Is this a bug? Or can Agda sometimes run forever? Or is something more subtle going on? 回答1: In fact

What are the drawbacks of encoding properties using functions?

五迷三道 提交于 2019-12-08 03:53:12
问题 In Agda, it seems that often there are two ways to refine a set. One is by simply writing a function that checks if a property holds, and lift. For example: has_true : List Bool -> Bool has_true (true ∷ xs) = true has_true (false ∷ xs) = has_true xs has_true [] = false Truthy : List Bool -> Set Truthy list = T (has_true list) Here, Truthy list is a proof that a boolean list has at least one true element. The other way is by encoding that property directly, as an inductive type: data Truthy :

Monadic substitution under binders

怎甘沉沦 提交于 2019-12-07 16:32:47
问题 In the following Agda code, I have a term language based on de Bruijn indices. I can define substitution over terms in the usual de Bruijn indices way, using renaming to allow the substitution to proceed under a binder. module Temp where data Type : Set where unit : Type _⇾_ : Type → Type → Type -- A context is a snoc-list of types. data Cxt : Set where ε : Cxt _∷_ : Cxt → Type → Cxt -- Context membership. data _∈_ (τ : Type) : Cxt → Set where here : ∀ {Γ} → τ ∈ Γ ∷ τ there : ∀ {Γ τ′} → τ ∈ Γ

Agda, type of proofs and with clause

谁说胖子不能爱 提交于 2019-12-07 11:58:28
问题 In AgdaIntro, the view section explains : ..that with doesn’t remember the connection between the with-term and the patterns. That means when you defines data False : Set where record True : Set where isTrue : Bool -> Set isTrue true = True isTrue false = False infixr 30 _:all:_ data All {A : Set}(P : A -> Set) : List A -> Set where all[] : All P [] _:all:_ : forall {x xs} -> P x -> All P xs -> All P (x :: xs) satisfies : {A : Set} -> (A -> Bool) -> A -> Set satisfies p x = isTrue (p x) data

What are the drawbacks of encoding properties using functions?

喜你入骨 提交于 2019-12-07 11:44:25
In Agda, it seems that often there are two ways to refine a set. One is by simply writing a function that checks if a property holds, and lift. For example: has_true : List Bool -> Bool has_true (true ∷ xs) = true has_true (false ∷ xs) = has_true xs has_true [] = false Truthy : List Bool -> Set Truthy list = T (has_true list) Here, Truthy list is a proof that a boolean list has at least one true element. The other way is by encoding that property directly, as an inductive type: data Truthy : List Bool -> Set where Here : (x : Bool) -> (x ≡ true) -> (xs : List Bool) -> Truthy (x ∷ xs) There :

Mimicking Haskell canonicity (one-instance only) of typeclasses in Agda

只愿长相守 提交于 2019-12-07 02:18:32
问题 Agda's mixiture of records and the instance keyword give us behaviour similar to that of Haskell's typeclasses. Moreover, ignoring the instance keyword, we can have more than one instance for the same type --- something we cannot do in Haskell. I am at a point where I need Haskell's one-instance only requirement, but in Agda. Is there an compiler option or some trick/heuristic to enforce this? Right now the approach I am taking is, record Yo (n : ℕ) : Set where field sem : (some interesting

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

自作多情 提交于 2019-12-07 01:15:17
问题 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