agda

Agda: Reading a line of standard input as a String instead of a Costring

倾然丶 夕夏残阳落幕 提交于 2019-12-04 06:44:47
I am trying to write a simple program that reads a line from standard input, reverses it, and then prints the reversed string. Unfortunately the native getLine function reads a Costring ; I can only reverse String s; and there is no function that takes a Costring to a String . How can I amend this program to compile? module EchoInputReverse where -- Agda standard library 0.7 open import Data.List using (reverse) open import Data.String open import Foreign.Haskell using (Unit) open import IO.Primitive postulate getLine : IO Costring {-# COMPILED getLine getLine #-} main : IO Unit main = getLine

How to extract the second element of Sigma on the Calculus of Constructions?

放肆的年华 提交于 2019-12-04 03:12:29
I'm attempting to do that as follows: λ (A : *) -> λ (B : (A -> *)) -> λ (t : (∀ (r : *) -> (∀ (x : a) -> (B x) -> r)) -> r) -> (t (B (t A (λ (x : A) -> λ (y : (B x)) -> x))) (λ (x : A) -> λ (y : (B x)) -> y)) Notice that, since the value returned by that function depends on a value inside the sigma itself, I need to extract that value. This code doesn't check, because, I believe, it fails to unify the type extracted from Sigma with the type inside it. Is there any workaround? 来源: https://stackoverflow.com/questions/43957592/how-to-extract-the-second-element-of-sigma-on-the-calculus-of

Type Hierarchy in Agda

[亡魂溺海] 提交于 2019-12-04 03:08:19
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! 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, does syntax highlighting and so on. Now, there is a command "Infer (deduce) type" available via C-c C-d ,

Use Agda's input method in other emacs mode?

纵饮孤独 提交于 2019-12-04 01:57:09
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 Add the following commands in your .emacs file: ;; Using the input method of Agda in LaTeX files. (require 'agda-input) (add-hook 'LaTeX-mode-hook (lambda () (set-input-method "Agda

A definition for finite sets in Agda

假装没事ソ 提交于 2019-12-04 00:16:50
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 understand this part of the paper. Thanks for taking the time to read my question. I appreciate it. data Fin

Path induction implied

一曲冷凌霜 提交于 2019-12-03 21:51:10
问题 This is a follow-up question to Getting path induction to work in Agda I wonder when that construct may be more expressive. It seems to me we can always express the same like so: f : forall {A} -> {x y : A} -> x == y -> "some type" f refl = instance of "some type" for p == refl Here Agda will do path induction given the example which is the same as c : (x : A) -> C refl from that question: pathInd : forall {A} -> (C : {x y : A} -> x == y -> Set) -> (c : (x : A) -> C refl) -> {x y : A} -> (p :

What's a good way to represent free groups?

Deadly 提交于 2019-12-03 15:43:44
It's easy to represent free magmas (binary leaf trees), free semigroups (non-empty lists), and free monoids (lists), and not hard to prove that they actually are what they claim to be. But free groups seem a lot trickier. There seem to be at least two approaches to using the usual List (Either a) representation: Encode in a type the requirement that if you have Left a :: Right b :: ... then Not (a = b) and the other way around. It seems likely to be a bit tough to build these. Work over an equivalence relation allowing arbitrary insertion/deletion of Left a :: Right a :: ... pairs (and the

Defining non-unary functions in Cubical mode

做~自己de王妃 提交于 2019-12-03 15:38:33
I'd like to define a function with two, higher inductive typed, arguments in Cubical mode. I am using the cubical package as my "prelude" library. I first define a quotient type for integers as a HIT: {-# OPTIONS --cubical #-} module _ where open import Data.Nat renaming (_+_ to _+̂_) open import Cubical.Core.Prelude data ℤ : Set where _-_ : (x : ℕ) → (y : ℕ) → ℤ quot : ∀ {x y x′ y′} → (x ℕ+ y′) ≡ (x′ ℕ+ y) → (x - y) ≡ (x′ - y′) I can then define a unary function using pattern matching: _+1 : ℤ → ℤ (x - y) +1 = suc x - y quot {x} {y} prf i +1 = quot {suc x} {y} (cong suc prf) i So far, so good

Haskell Deriving Mechanism for Agda

ⅰ亾dé卋堺 提交于 2019-12-03 15:26:11
I am wondering if there is anything in Agda that resembles Haskell's deriving Eq clause ---then I have an associated question below, as well. For example, suppose I have types for a toy-language, data Type : Set where Nat : Type Prp : Type Then I can implement decidable equality by pattern matching and C-c C-a , _≟ₜ_ : Decidable {A = Type} _≡_ Nat ≟ₜ Nat = yes refl Nat ≟ₜ Prp = no (λ ()) Prp ≟ₜ Nat = no (λ ()) Prp ≟ₜ Prp = yes refl I'm curious if this can be mechanised or automated somehow similar to the manner it is done in Haskell: data Type = Nat | Prp deriving Eq Thank-you! While we're on

How do I prove a “seemingly obvious” fact when relevant types are abstracted by a lambda in Idris?

不羁的心 提交于 2019-12-03 12:03:09
问题 I am writing a basic monadic parser in Idris, to get used to the syntax and differences from Haskell. I have the basics of that working just fine, but I am stuck on trying to create VerifiedSemigroup and VerifiedMonoid instances for the parser. Without further ado, here's the parser type, Semigroup, and Monoid instances, and the start of a VerifiedSemigroup instance. data ParserM a = Parser (String -> List (a, String)) parse : ParserM a -> String -> List (a, String) parse (Parser p) = p