agda

Is it possible to use Agda as a library?

 ̄綄美尐妖づ 提交于 2019-12-01 21:07:29
Instead of using Agda on a filesystem (with EMACS, terminal, etc.), is it possible to use it directly from Haskell, as a library? For example: -- UsingAgda.hs import Agda -- Prints the type of a term on some Agda code main :: IO () main = typeOf "true" agdaCode where agdaCode :: String agdaCode = unlines ["module Hello where " ," " ,"data Bool : Set where" ," true : Bool " ," false : Bool "] The code above would output Bool , because true : Bool on that Agda code. Yes, it is possible. Agda was designed as a Haskell library plus a main module. You can see a couple of small examples here . As a

How can finite numbers work? (dependent types)

纵饮孤独 提交于 2019-12-01 18:14:05
I'm interested in dependently typed languages. Finite numbers seem very usable to me. For example, to safely index fixed-size arrays. But the definition is not clear for me. The data type for finite numbers in Idris can be the following: (And probably similar in Agda) data FiniteNum : Natural -> Type where FZero : FiniteNum (Succ k) FSucc : FiniteNum k -> FiniteNum (Succ k) And it seems to work: exampleFN : FiniteNum (Succ (Succ Zero)) exampleFN = FSucc FZero -- typechecks -- exampleFN = FSucc (FSucc FZero) -- won't typecheck But how does this work? What does k mean? And how come that the type

How can finite numbers work? (dependent types)

白昼怎懂夜的黑 提交于 2019-12-01 16:49:34
问题 I'm interested in dependently typed languages. Finite numbers seem very usable to me. For example, to safely index fixed-size arrays. But the definition is not clear for me. The data type for finite numbers in Idris can be the following: (And probably similar in Agda) data FiniteNum : Natural -> Type where FZero : FiniteNum (Succ k) FSucc : FiniteNum k -> FiniteNum (Succ k) And it seems to work: exampleFN : FiniteNum (Succ (Succ Zero)) exampleFN = FSucc FZero -- typechecks -- exampleFN =

Agda: parse a string with numbers

不打扰是莪最后的温柔 提交于 2019-12-01 06:28:47
I am trying to parse a string with natural numbers in Agda. e.g., the result of stringListToℕ "1,2,3" should be Just (1 ∷ 2 ∷ 3 ∷ []) My current code is not quite right or by any means nice, but it works. However it returns the type: Maybe (List (Maybe ℕ)) The Question is: How to implement the function stringListToℕ in a nice way (compared to my code); it should have the type Maybe (List ℕ) (optional, not important) How can I convert the type Maybe (List (Maybe ℕ)) to Maybe (List ℕ) ? My Code: charToℕ : Char → Maybe ℕ charToℕ '0' = just 0 charToℕ '1' = just 1 charToℕ '2' = just 2 charToℕ '3' =

Agda: parse a string with numbers

陌路散爱 提交于 2019-12-01 05:15:34
问题 I am trying to parse a string with natural numbers in Agda. e.g., the result of stringListToℕ "1,2,3" should be Just (1 ∷ 2 ∷ 3 ∷ []) My current code is not quite right or by any means nice, but it works. However it returns the type: Maybe (List (Maybe ℕ)) The Question is: How to implement the function stringListToℕ in a nice way (compared to my code); it should have the type Maybe (List ℕ) (optional, not important) How can I convert the type Maybe (List (Maybe ℕ)) to Maybe (List ℕ) ? My Code

Path induction implied

主宰稳场 提交于 2019-11-30 23:53:56
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 : x == y) -> C p It seems this function is isomorphic to: f' : forall {A} -> {x y : A} -> x == y ->

Do agda programs necessarily terminate?

怎甘沉沦 提交于 2019-11-30 22:33:32
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? In fact, there are compilation errors. The agda executable finds an error and passes that information to agda-mode

≡-Reasoning and 'with' patterns

久未见 提交于 2019-11-30 16:48:28
问题 I was proving some properties of filter and map , everything went quite good until I stumbled on this property: filter p (map f xs) ≡ map f (filter (p ∘ f) xs) . Here's a part of the code that's relevant: open import Relation.Binary.PropositionalEquality open import Data.Bool open import Data.List hiding (filter) import Level filter : ∀ {a} {A : Set a} → (A → Bool) → List A → List A filter _ [] = [] filter p (x ∷ xs) with p x ... | true = x ∷ filter p xs ... | false = filter p xs Now, because

“Strictly positive” in Agda

为君一笑 提交于 2019-11-30 12:44:25
问题 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

Agda Type-Checking and Commutativity / Associativity of +

为君一笑 提交于 2019-11-30 06:29:15
Since the _+_ -Operation for Nat is usually defined recursively in the first argument, its obviously non-trivial for the type-checker to know that i + 0 == i . However, I frequently run into this issue when I write functions on fixed-size Vectors. One example: How can I define an Agda-function swap : {A : Set}{m n : Nat} -> Vec A (n + m) -> Vec A (m + n) which puts the first n values at the end of the vector? Since a simple solution in Haskell would be swap 0 xs = xs swap n (x:xs) = swap (n-1) (xs ++ [x]) I tried it analogously in Agda like this: swap : {A : Set}{m n : Nat} -> Vec A (n + m) ->