agda

Agda, type of proofs and with clause

旧城冷巷雨未停 提交于 2019-12-05 19:19:33
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 Find {A : Set}(p : A -> Bool) : List A -> Set where found : (xs : List A)(y : A) -> satisfies p y ->

Getting path induction to work in Agda

谁说胖子不能爱 提交于 2019-12-05 13:07:59
I can't figure out why my path induction isn't type checking correctly. It says "C x should be a function type, but it isn't" when referring to C (refl x). Perhaps my definition of refl is wrong or is there something wrong with my {}'s and ()'s? data _≡_ {A : Set}(a : A) : A → Set where refl : a ≡ a infix 4 _≡_ pathInd : ∀ {u} → {A : Set} → (C : {x y : A} → x ≡ y → Set u) → (c : (x : A) → C (refl x)) → ({x y : A} (p : x ≡ y) → C p) pathInd C c (refl x) = c x refl is not a function. Here is the definition you need: pathInd : ∀ {u} → {A : Set} → (C : {x y : A} → x ≡ y → Set u) → (c : (x : A) → C

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

混江龙づ霸主 提交于 2019-12-05 06:41:48
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 between 4 and len Is there a way to define myVec in Idris without manually specifying the index of the

Separation of Concerns: when is it best to disassociate semantics from syntax?

萝らか妹 提交于 2019-12-05 02:00:23
问题 Choices Typeclasses are brilliant in that they allow us to adjoin extra structure to existing types. Thereby allowing us to defer some design decisions rather than making rushed decision at the time of conception. On the other hand, in object oriented programming, for example, we are forced to consider what a type needs to do immediately and any additional structure that is apparent, or needed, at a later time would be incorporated into a subtype. Everything has its purposes. I'm wondering

Are there examples Agda code running in production? [closed]

我只是一个虾纸丫 提交于 2019-12-04 22:14:31
Agda is a nice programming language to explore dependent types and play around with intuitionistic type theory and to experiment with the implementation of these things. But are there already examples for “real” programs written in Agda? Maybe even examples that show off its features (similar to how xmonad is often mentioned as an example of a “real” Haskell program)? 来源: https://stackoverflow.com/questions/10931316/are-there-examples-agda-code-running-in-production

Agda functions, function matching on types

蹲街弑〆低调 提交于 2019-12-04 17:10:31
I want to create a helper function, that will take a term from a an indexed or parametrized type and return that type parameter. showLen : {len : ℕ} {A : Set} -> Vec A len -> ℕ showLen ? = len showType : {len : ℕ} {A : Set} -> Vec A len -> Set showType ? = A Is this possible? (I can see how showType [] might have issues, but what about when the Type is indexed?) If you get rid of the implicit arguments, you can implement this quite easily: showLen : (len : ℕ) (A : Set) → Vec A len → ℕ showLen len _ _ = len In fact, we can do both at once: open import Data.Product showBoth : (len : ℕ) (A : Set)

Pattern matching in Observational Type Theory

帅比萌擦擦* 提交于 2019-12-04 16:32:05
问题 In the end of the "5. Full OTT" section of Towards Observational Type Theory the authors show how to define coercible-under-constructors indexed data types in OTT. The idea is basically to turn indexed data types into parameterized like this: data IFin : ℕ -> Set where zero : ∀ {n} -> IFin (suc n) suc : ∀ {n} -> IFin n -> IFin (suc n) data PFin (m : ℕ) : Set where zero : ∀ {n} -> suc n ≡ m -> PFin m suc : ∀ {n} -> suc n ≡ m -> PFin n -> PFin m Conor also mentions this technique at the bottom

refl in agda : explaining congruence property

感情迁移 提交于 2019-12-04 15:09:08
With the following definition of equality, we have refl as constructor data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x and we can prove that function are congruent on equality cong : ∀ { a b} { A : Set a } { B : Set b } (f : A → B ) {m n} → m ≡ n → f m ≡ f n cong f refl = refl I am not sure I can parse what is going on exactly here. I think we are pattern matching refl on hidden parameters : if we replace the first occurence by refl by another identifier, we get a type error. after pattern matching, I imagine that m and n are the same by the definition of refl. then magic

Modeling the ST monad in Agda

情到浓时终转凉″ 提交于 2019-12-04 10:32:01
问题 This recent SO question prompted me to write an unsafe and pure emulation of the ST monad in Haskell, a slightly modified version of which you can see below: {-# LANGUAGE DeriveFunctor, GeneralizedNewtypeDeriving, RankNTypes #-} import Control.Monad.Trans.State import GHC.Prim (Any) import Unsafe.Coerce (unsafeCoerce) import Data.List newtype ST s a = ST (State ([Any], Int) a) deriving (Functor, Applicative, Monad) newtype STRef s a = STRef Int deriving Show newSTRef :: a -> ST s (STRef s a)

How can I establish a bijection between a tree and its traversal?

元气小坏坏 提交于 2019-12-04 10:31:11
问题 I was looking at How does inorder+preorder construct unique binary tree? and thought it would be fun to write a formal proof of it in Idris. Unfortunately, I got stuck fairly early on, trying to prove that the ways to find an element in a tree correspond to the ways to find it in its inorder traversal (of course, I'll also need to do that for the preorder traversal). Any ideas would be welcome. I'm not particularly interested in a complete solution—more just help getting started in the right