idris

Converting Coq to Idris

允我心安 提交于 2019-12-04 08:09:18
问题 What would be some useful guidelines for converting Coq source to Idris (e.g. how similar are their type systems and what can be made of translating the proofs)? From what I gather, Idris' built-in library of tactics is minimal yet extendable, so I suppose with some extra work this should be possible. 回答1: I've recently translated a chunk of Software Foundations and did a partial port of {P|N|Z}Arith, some observations I've made in the process: Generally using Idris tactics (in their Pruvloj

How to encode possible state transitions in type?

二次信任 提交于 2019-12-04 03:51:34
I am trying to replicate in Haskell this piece of Idris code, which enforces correct sequencing of actions through types: data DoorState = DoorClosed | DoorOpen data DoorCmd : Type -> DoorState -> DoorState -> Type where Open : DoorCmd () DoorClosed DoorOpen Close : DoorCmd () DoorOpen DoorClosed RingBell : DoorCmd () DoorClosed DoorClosed Pure : ty -> DoorCmd ty state state (>>=) : DoorCmd a state1 state2 -> (a -> DoorCmd b state2 state3) -> DoorCmd b state1 state3 Thanks to overloading of (>>=) operator, one can write monadic code like: do Ring Open Close but compiler rejects incorrect

In Idris, is “Eq a” a type, and can I supply a value for it?

a 夏天 提交于 2019-12-04 03:24:33
问题 In the following, example1 is standard syntax (as documented), with Eq a as a constraint. In example2 , I specify Eq a directly as the type of a parameter, and the compiler accepts it. However it is unclear what I can specify as a value of that type. For a specific type a , eg Nat , I assume it would make sense to somehow specify an implementation of Eq Nat , either the default implementation, or some other named implementation. %default total example1: Eq a => (x : a) -> (y : a) -> Type

How to extract the second element of Sigma on the Calculus of Constructions?

放肆的年华 提交于 2019-12-04 03:12:29
I'm attempting to do that as follows: λ (A : *) -> λ (B : (A -> *)) -> λ (t : (∀ (r : *) -> (∀ (x : a) -> (B x) -> r)) -> r) -> (t (B (t A (λ (x : A) -> λ (y : (B x)) -> x))) (λ (x : A) -> λ (y : (B x)) -> y)) Notice that, since the value returned by that function depends on a value inside the sigma itself, I need to extract that value. This code doesn't check, because, I believe, it fails to unify the type extracted from Sigma with the type inside it. Is there any workaround? 来源: https://stackoverflow.com/questions/43957592/how-to-extract-the-second-element-of-sigma-on-the-calculus-of

Is there a nice way to use `->` directly as a function in Idris?

随声附和 提交于 2019-12-04 02:05:05
One can return a type in a function in Idris, for example t : Type -> Type -> Type t a b = a -> b But the situation came up (when experimenting with writing some parsers) that I wanted to use -> to fold a list of types, ie typeFold : List Type -> Type typeFold = foldr1 (->) So that typeFold [String, Int] would give String -> Int : Type . This doesn't compile though: error: no implicit arguments allowed here, expected: ")", dependent type signature, expression, name typeFold = foldr1 (->) ^ But this works fine: t : Type -> Type -> Type t a b = a -> b typeFold : List Type -> Type typeFold =

What is the preferred alternative to Fin from Idris in Haskell

馋奶兔 提交于 2019-12-04 01:43:57
I would like to have a type which can contain values 0 to n, where n lives on the type level. I was trying something like: import GHC.TypeLits import Data.Proxy newtype FiniteNat n = FiniteNat { toInteger :: Integer } smartConstructFiniteNat :: (KnownNat n) => Proxy n -> Integer -> Maybe (FiniteNat (Proxy n)) smartConstructFiniteNat pn i | 0 <= i && i < n = Just (FiniteNat i) | otherwise = Nothing where n = natVal pn which works basically, but it's not really satisfying somehow. Is there a "standard" solution, or even a library to achieve this? There is a lot of fuss about dependenty typed

Haskell version of Idris !-notation (bang notation)

孤人 提交于 2019-12-04 01:38:41
I've had the luxury of learning a bit of Idris lately and one thing I've found extremely convenient is the !-notation, which let's me shorten monadic code inside a do block such as a' <- a b' <- b c' <- c someFunction a' b' c' to the much nicer someFunction !a !b !c Now when I write code in Haskell, I'm looking for something similar but as far as I can tell it doesn't exist (and the bang character is obviously already used for strict pattern matching). Is there any way to avoid having a bunch of trivial left arrows inside a do block? Perhaps an extension that adds a rewriting rule, or

(xs : Vect n elem) -> Vect (n * 2) elem

非 Y 不嫁゛ 提交于 2019-12-03 16:41:19
The book Type Driven Development with Idris presents this exercise: Define a possible method that fits the signature: two : (xs : Vect n elem) -> Vect (n * 2) elem I tried: two : (xs : Vect n elem) -> Vect (n * 2) elem two xs = xs ++ xs But I got the following error: *One> :r Type checking ./One.idr One.idr:9:5:When checking right hand side of two: Type mismatch between Vect (n + n) elem (Type of xs ++ xs) and Vect (mult n 2) elem (Expected type) Specifically: Type mismatch between plus n n and mult n 2 Holes: Hw1.two If I have a Vector of size N, and need a Vector of size N*2, then appending

What's a good way to represent free groups?

Deadly 提交于 2019-12-03 15:43:44
It's easy to represent free magmas (binary leaf trees), free semigroups (non-empty lists), and free monoids (lists), and not hard to prove that they actually are what they claim to be. But free groups seem a lot trickier. There seem to be at least two approaches to using the usual List (Either a) representation: Encode in a type the requirement that if you have Left a :: Right b :: ... then Not (a = b) and the other way around. It seems likely to be a bit tough to build these. Work over an equivalence relation allowing arbitrary insertion/deletion of Left a :: Right a :: ... pairs (and the

How do I prove a “seemingly obvious” fact when relevant types are abstracted by a lambda in Idris?

不羁的心 提交于 2019-12-03 12:03:09
问题 I am writing a basic monadic parser in Idris, to get used to the syntax and differences from Haskell. I have the basics of that working just fine, but I am stuck on trying to create VerifiedSemigroup and VerifiedMonoid instances for the parser. Without further ado, here's the parser type, Semigroup, and Monoid instances, and the start of a VerifiedSemigroup instance. data ParserM a = Parser (String -> List (a, String)) parse : ParserM a -> String -> List (a, String) parse (Parser p) = p