idris

Idris : Is it possible to rewrite all functions using “with” to use “case” instead of “with” ? If not, could you give a counter example?

六眼飞鱼酱① 提交于 2019-12-01 18:03:52
问题 In Idris, is it possible to rewrite all functions using "with" to use "case" instead of "with" ? If not, could you give a counter example ? 回答1: Not possible. When you pattern match with with , the types in the context are updated with information extracted from the matched constructor. case doesn't cause such updating. As an example, the following works with with but not with case : import Data.So -- here (n == 10) in the goal type is rewritten to True or False -- after the match maybeTen :

Idris : Is it possible to rewrite all functions using “with” to use “case” instead of “with” ? If not, could you give a counter example?

不羁的心 提交于 2019-12-01 17:45:18
In Idris, is it possible to rewrite all functions using " with " to use "case" instead of "with" ? If not, could you give a counter example ? Not possible. When you pattern match with with , the types in the context are updated with information extracted from the matched constructor. case doesn't cause such updating. As an example, the following works with with but not with case : import Data.So -- here (n == 10) in the goal type is rewritten to True or False -- after the match maybeTen : (n : Nat) -> Maybe (So (n == 10)) maybeTen n with (n == 10) maybeTen n | False = Nothing maybeTen n | True

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 =

Prove map id = id in idris?

落花浮王杯 提交于 2019-12-01 14:35:57
问题 I'm just starting playing with idris and theorem proving in general. I can follow most of the examples of proofs of basic facts on the internet, so I wanted to try something arbitrary by my own. So, I want to write a proof term for the following basic property of map: map : (a -> b) -> List a -> List b prf : map id = id Intuitively, I can imagine how the proof should work: Take an arbitrary list l and analyze the possibilities for map id l. When l is empty, it's obvious; when l is non-empty

In Idris, how do I hide something defined in Prelude?

人走茶凉 提交于 2019-12-01 04:16:10
I want to define my own version of fib to play around with, but fib is exported by the Prelude . How do I hide the import from the Prelude ? In Haskell I would write import Prelude hiding (fib) , but that doesn't work in Idris. As this Idris mailing post suggests: At the minute, all there is the (as yet undocumented) %hide directive, which makes a name inaccessible. Here is an example: %hide fib fib : Nat -> Nat fib Z = Z fib (S Z) = S Z fib (S (S n)) = fib n + fib (S n) 来源: https://stackoverflow.com/questions/43878995/in-idris-how-do-i-hide-something-defined-in-prelude

In Idris, how do I hide something defined in Prelude?

笑着哭i 提交于 2019-12-01 00:43:12
问题 I want to define my own version of fib to play around with, but fib is exported by the Prelude . How do I hide the import from the Prelude ? In Haskell I would write import Prelude hiding (fib) , but that doesn't work in Idris. 回答1: As this Idris mailing post suggests: At the minute, all there is the (as yet undocumented) %hide directive, which makes a name inaccessible. Here is an example: %hide fib fib : Nat -> Nat fib Z = Z fib (S Z) = S Z fib (S (S n)) = fib n + fib (S n) 来源: https:/

Idris non-trivial type computation for tensor indexing

穿精又带淫゛_ 提交于 2019-11-30 19:27:04
问题 I've been messing around with a simple tensor library, in which I have defined the following type. data Tensor : Vect n Nat -> Type -> Type where Scalar : a -> Tensor [] a Dimension : Vect n (Tensor d a) -> Tensor (n :: d) a The vector parameter of the type describes the tensor's "dimensions" or "shape". I am currently trying to define a function to safely index into a Tensor . I had planned to do this using Fin s but I ran into an issue. Because the Tensor is of unknown order, I could need

Is it possible to derive induction for the church-encoded Nat?

余生长醉 提交于 2019-11-29 19:52:41
问题 I was just wondering if it is possible to derive induction for the church-encoded Nat type on Idris, Agda, Coq and similar. Notice this is a different issue from doing it on CoC (which is known to be impossible) because we have much more expressivity on those (we're able to, for example, extract the second element of Sigma). Here is a poor proof sketch on Idris (had a lot of syntax issues): CN : Type CN = (t : Type) -> t -> (t -> t) -> t CS : CN -> CN CS n t z s = s (n t z s) CZ : CN CZ t z s

Differences between Agda and Idris

☆樱花仙子☆ 提交于 2019-11-29 19:02:46
I'm starting to dive into dependently-typed programming and have found that the Agda and Idris languages are the closest to Haskell, so I started there. My question is: which are the main differences between them? Are the type systems equally expresive in both of them? It would be great to have a comprehensive comparative and a discussion about benefits. I've been able to spot some: Idris has type classes à la Haskell, whereas Agda goes with instance arguments Idris includes monadic and applicative notation Both of them seem to have some sort of rebindable syntax, although not really sure if

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

左心房为你撑大大i 提交于 2019-11-29 07:54:45
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 than ℕ s, the function becomes quadratic: enumerate-Fin : ∀ {α} {A : Set α} -> (xs : List A) -> List (Fin