idris

Open Type Level Proofs in Haskell/Idris

僤鯓⒐⒋嵵緔 提交于 2019-12-02 20:45:15
In Idris/Haskell, one can prove properties of data by annotating the types and using GADT constructors, such as with Vect, however, this requires hardcoding the property into the type (e.g. a Vect has to be a separate type from a List). Is it possible to have types with an open set of properties (such as list carrying both a length and running average), for example by overloading constructors or using something in the vein of Effect? I believe that McBride has answered that question (for Type Theory) in his ornament paper (pdf) . The concept you are looking for is the one of an algebraic

Dependent types can prove your code is correct up to a specification. But how do you prove the specification is correct?

北慕城南 提交于 2019-12-02 18:43:22
Dependent types are often advertised as a way to enable you to assert that a program is correct up to a specification. So, for example, you are asked to write a code that sorts a list - you are able to prove that code is correct by encoding the notion of "sort" as a type, and writing a function such as List a -> SortedList a . But how do you prove that the specification, SortedList , is correct? Wouldn't it be the case that, the more complex your specification is, the more likely it would be that your encoding of that specification as a type is incorrect? This is the static, type-system

Why haven't newer dependently typed languages adopted SSReflect's approach?

对着背影说爱祢 提交于 2019-12-02 17:33:52
There are two conventions I've found in Coq's SSReflect extension that seem particularly useful but which I haven't seen widely adopted in newer dependently-typed languages (Lean, Agda, Idris). Firstly, where possible predicates are expressed as boolean-returning functions rather than inductively defined datatypes. This brings decidability by default, opens up more opportunities for proof by computation, and improves checking performance by avoiding the need for the proof engine to carry around large proof terms. The main disadvantage I see is the need to use reflection lemmas to manipulate

Dependent Types: How is the dependent pair type analogous to a disjoint union?

天大地大妈咪最大 提交于 2019-12-02 15:07:40
I've been studying dependent types and I understand the following: Why universal quantification is represented as a dependent function type. ∀(x:A).B(x) means “for all x of type A there is a value of type B(x) ” . Hence it's represented as a function which when given any value x of type A returns a value of type B(x) . Why existential quantification is represented as a dependent pair type. ∃(x:A).B(x) means “there exists an x of type A for which there is a value of type B(x) ” . Hence it's represented as a pair whose first element is a particular value x of type A and whose second element is a

Where to start with dependent type programming? [closed]

风流意气都作罢 提交于 2019-12-02 14:14:32
There is an Idris tutorial, an Agda tutorial and many other tutorial style papers and introductory material with never ending references to things yet to learn. I'm kind of crawling in the middle of all these and most of the time I'm stuck with mathematical notations and new terminology appearing suddenly with no explanation. Perhaps my math sucks :-) Is there any disciplined way to approach dependent type programming? Like when you want to learn Haskell, you start with "Teach yourself a Haskell", when you want to learn Scala, you start with Odersky's book, for Ruby you read that weird

Function to Determine if Nat is Divisible by 5 at Compile-Time

孤街浪徒 提交于 2019-12-02 07:23:50
问题 Using Cactus's helpful answer, I tried to write a function that, given a Nat , will return that Nat if it's divisible by 5 . onlyModBy5Helper : (n : Nat) -> (k : Nat ** k `mod` 5 = 0) -> Nat onlyModBy5Helper n k = n And then the primary function: onlyModBy5 : Nat onlyModBy5 = onlyModBy5Helper 10 (10 ** Refl) However, that failed with a compile-time error: When checking right hand side of onlyModBy5 with expected type Nat When checking argument pf to constructor Builtins.MkDPair: Type mismatch

Understanding `k : Nat ** 5 * k = n` Signature

吃可爱长大的小学妹 提交于 2019-12-02 05:33:41
问题 The following function compiles: onlyModByFive : (n : Nat) -> (k : Nat ** 5 * k = n) -> Nat onlyModByFive n k = 100 But what does k represent with its Nat ** 5 * k = n syntax? Also, how can I call it? Here's what I tried, but I don't understand the output. *Test> onlyModByFive 5 5 When checking an application of function Main.onlyModByFive: (k : Nat ** plus k (plus k (plus k (plus k (plus k 0)))) = 5) is not a numeric type source of answer - https://groups.google.com/d/msg/idris-lang

How can I express range validity in Idris?

拜拜、爱过 提交于 2019-12-02 02:40:14
I am trying to model a simple survey form in Idris and currently struggling with validating user input, which comes as a string, w.r.t. to the type of questions asked. Currently I have the following types: data Question : Type where QCM : {numOptions : Nat} -> (question : String) -> (qcmOptions : Vect numOptions String) -> (expected : Fin numOptions) -> Question data Answer : (q : Question) -> Type where AnswerQCM : (option : Fin n) -> Answer (QCM {numOptions = n } q opts exp) total isCorrectAnswer : (q : Question ) -> Answer q -> Bool isCorrectAnswer (QCM {numOptions} question qcmOptions

Understanding `k : Nat ** 5 * k = n` Signature

这一生的挚爱 提交于 2019-12-02 00:50:46
The following function compiles: onlyModByFive : (n : Nat) -> (k : Nat ** 5 * k = n) -> Nat onlyModByFive n k = 100 But what does k represent with its Nat ** 5 * k = n syntax? Also, how can I call it? Here's what I tried, but I don't understand the output. *Test> onlyModByFive 5 5 When checking an application of function Main.onlyModByFive: (k : Nat ** plus k (plus k (plus k (plus k (plus k 0)))) = 5) is not a numeric type source of answer - https://groups.google.com/d/msg/idris-lang/ZPi9wCd95FY/eo3tRijGAAAJ (k : Nat) ** (5 * k = n) is a dependent pair consisting of A first element k : Nat 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