idris

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

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

China☆狼群 提交于 2019-11-28 01:44:53
问题 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

So: what's the point?

此生再无相见时 提交于 2019-11-27 13:31:51
What is the intended purpose of the So type? Transliterating into Agda: data So : Bool → Set where oh : So true So lifts a Boolean proposition up to a logical one. Oury and Swierstra's introductory paper The Power of Pi gives an example of a relational algebra indexed by the tables' columns. Taking the product of two tables requires that they have different columns, for which they use So : Schema = List (String × U) -- U is the universe of SQL types -- false iff the schemas share any column names disjoint : Schema -> Schema -> Bool disjoint = ... data RA : Schema → Set where -- ... Product : ∀

Concatenation of two vectors - why are lengths not treated as commutative?

走远了吗. 提交于 2019-11-27 08:21:10
问题 I'm playing around with Idris and I came across something which confuses me a little: The following type checks: conc : Vect n a -> Vect m a -> Vect (n+m) a conc [] ys = ys conc (x :: xs) ys = x :: (conc xs ys) but this doesn't: conc : Vect n a -> Vect m a -> Vect (m+n) a conc [] ys = ys conc (x :: xs) ys = x :: (conc xs ys) with the following error: When checking right hand side of conc with expected type Vect (m + 0) a Type mismatch between Vect m a (Type of ys) and Vect (plus m 0) a

Helper Function to Determine if Nat `mod` 5 == 0

半世苍凉 提交于 2019-11-27 07:26:11
问题 Xash provided me with a helpful answer on Function to Determine if Nat is Divisible by 5 at Compile-Time (that I re-named from my original long name): onlyModBy5 : (n : Nat) -> n `modNat` 5 = 0 -> Nat onlyModBy5 n prf = n A previous answer educated me how to run it on the REPL using the Refl argument: -- 5 % 5 == 0, so it should compile *Test> onlyModBy5 5 Refl 5 : Nat -- 7 % 5 == 2, so it should not compile *Test> onlyModBy5 7 Refl (input):1:12:When checking an application of function Main

Difference between type parameters and indices?

*爱你&永不变心* 提交于 2019-11-27 03:58:15
I am new to dependent types and am confused about the difference between the two. It seems people usually say a type is parameterized by another type and indexed by some value . But isn't there no distinction between types and terms in a dependently typed language? Is the distinction between parameters and indices fundamental? Can you show me examples showing difference in their meanings in both programming and theorem proving? When you see a family of types, you may wonder whether each of the arguments it has are parameters or indices . Parameters are merely indicative that the type is

Why is typecase a bad thing? [closed]

早过忘川 提交于 2019-11-26 22:41:15
问题 Both Agda and Idris effectively prohibit pattern matching on values of type Type . It seems that Agda always matches on the first case, while Idris just throws an error. So, why is typecase a bad thing? Does it break consistency? I haven't been able to find much information regarding the topic. 回答1: It's really odd that people think pattern matching on types is bad. We get a lot of mileage out of pattern matching on data which encode types, whenever we do a universe construction. If you take

So: what's the point?

别等时光非礼了梦想. 提交于 2019-11-26 18:15:18
问题 What is the intended purpose of the So type? Transliterating into Agda: data So : Bool → Set where oh : So true So lifts a Boolean proposition up to a logical one. Oury and Swierstra's introductory paper The Power of Pi gives an example of a relational algebra indexed by the tables' columns. Taking the product of two tables requires that they have different columns, for which they use So : Schema = List (String × U) -- U is the universe of SQL types -- false iff the schemas share any column