idris

How to prove that a string is in hexadecimal format?

删除回忆录丶 提交于 2019-12-24 18:16:53
问题 How can I use Idris to build a function that, given a string, returns a proof that such String is hexadecimal (i.e., 0x followed by 2*N characters from 0-9 and a-f , such as "0x1a7f33b8" )? What I tried First, I've constructed the following type for hex chars: data IsNib : Char -> Type where IsNib0 : IsNib '0' IsNib1 : IsNib '1' IsNib2 : IsNib '2' IsNib3 : IsNib '3' IsNib4 : IsNib '4' IsNib5 : IsNib '5' IsNib6 : IsNib '6' IsNib7 : IsNib '7' IsNib8 : IsNib '8' IsNib9 : IsNib '9' IsNibA : IsNib

How to write a simple list-based quicksort in Idris?

陌路散爱 提交于 2019-12-24 03:01:10
问题 I'm just trying to do the bare minimum to translate the following Haskell to Idris (I'm not looking for efficiency or proofs of correctness): quicksort [] = [] quicksort (x:xs) = quicksort [y | y <- xs, y<x ] ++ [x] ++ quicksort [y | y <- xs, y>=x] Here's the Idris code I have, which is essentially unchanged from the Haskell except for needing to tell Idris that we are dealing with Ordered types: quicksort: List (Ord b) -> List (Ord b) quicksort [] = [] quicksort (x::xs) = quicksort [y | y <-

How to write a simple list-based quicksort in Idris?

橙三吉。 提交于 2019-12-24 03:01:08
问题 I'm just trying to do the bare minimum to translate the following Haskell to Idris (I'm not looking for efficiency or proofs of correctness): quicksort [] = [] quicksort (x:xs) = quicksort [y | y <- xs, y<x ] ++ [x] ++ quicksort [y | y <- xs, y>=x] Here's the Idris code I have, which is essentially unchanged from the Haskell except for needing to tell Idris that we are dealing with Ordered types: quicksort: List (Ord b) -> List (Ord b) quicksort [] = [] quicksort (x::xs) = quicksort [y | y <-

Idris - map function on custom dependent data type fails

放肆的年华 提交于 2019-12-24 01:47:07
问题 I am relatively new to idris and dependent-types and I encountered the following problem - I created a custom data type similar to vectors: infixr 1 ::: data TupleVect : Nat -> Nat -> Type -> Type where Empty : TupleVect Z Z a (:::) : (Vect o a, Vect p a) -> TupleVect n m a -> TupleVect (n+o) (m+p) a exampleTupleVect : TupleVect 5 4 Int exampleTupleVect = ([1,2], [1]) ::: ([3,4],[2,3]) ::: ([5], [4]) ::: Empty It is inductively constructed by adding tuples of vectors and indexed by the sum of

Surprising failure of unification in Idris

≡放荡痞女 提交于 2019-12-24 00:56:55
问题 I'm trying to make what one might call a decidable parser in Idris. At first I am just looking at parsing natural numbers, but have ran into an unexpected problem. A minimum example of the code that produces it is this: data Digit : Char -> Type where Zero : Digit '0' One : Digit '1' digitToNat : Digit a -> Nat digitToNat Zero = 0 digitToNat One = 1 natToChar : Nat -> Char natToChar Z = '0' natToChar (S Z) = '1' natToDigit : (n : Nat) -> Digit (natToChar n) natToDigit Z = Zero natToDigit (S Z

Pattern matching on Type in Idris

会有一股神秘感。 提交于 2019-12-23 18:04:17
问题 Probably it's elementary but I don't understand why the following function answers 1 for fnc Nat and also, for fnc Integer , which is not even included as a pattern. fnc : Type -> Integer fnc Bool = 1 fnc Nat = 2 回答1: You can't pattern match on type and you shouldn't. When I compile your code I receive next error: warning - Unreachable case: fnc Nat This was already discussed earlier: Old discussion. Some similar question. Some similar issue on GitHub. UPDATE: Finally found more relevant

implementation of BigDecimal in idris

隐身守侯 提交于 2019-12-23 12:03:54
问题 I'm trying to implement a bigdecimal in Idris. I have this so far: -- a big decimal has a numerator and a 10^x value -- it has one type for zero, --TODO the numerator can't be zero for any other case --TODO and it can't be divisible by 10 data BigDecimal : (num : Integer) -> (denExp : Integer) -> Type where Zero : BigDecimal 0 0 BD : (n : Integer) -> (d : Integer) -> BigDecimal n d I would like to force the restrictions marked by "TODO" above. However, I'm am just learning Idris, so I'm not

Plus vs S in a function type

走远了吗. 提交于 2019-12-22 10:43:28
问题 The following declaration of vector cons cons : a -> Vect n a -> Vect (n + 1) a cons x xs = x :: xs fails with the error Type mismatch between S n and plus n 1 while the following vector append compiles and works append : Vect n a -> Vect m a -> Vect (n + m) a append xs ys = xs ++ ys Why type-level plus is accepted for the second case but not for the first. What's the difference? 回答1: Why does x :: xs : Vect (n + 1) a lead to a type error? (+) is defined by induction on its first argument so

Using heterogenous equality with =

做~自己de王妃 提交于 2019-12-22 09:03:36
问题 What I have so far is: module Foo postulate P : 'P postulate NP : 'NP complexityProof : P = NP complexityProof = ?complexityProof_rhs But on trying to load the file, I just get: When elaborating type of Foo.complexityProof: When elaborating argument y to type constructor =: Can't unify 'NP with 'P Specifically: Can't unify "NP" with "P" A little suprised at the error, as I thought Idris, having heterogeneous "John Major" equality, was fine with differing types on the left and right-hand side

Quicksort in Idris

限于喜欢 提交于 2019-12-21 21:09:41
问题 I'm learning Idris and I thought I'd try to implement Quicksort for Vect types. But I'm having a hard time with the utility method that should, given a pivot element and a vector, split the vector in two, one with the elements ≤ pivot and another with those > pivot. This is trivial for lists: splitListOn : Ord e => (pivot : e) -> List e -> (List e, List e) splitListOn pivot [] = ([], []) splitListOn pivot (x :: xs) = let (ys, zs) = splitListOn pivot xs in if x <= pivot then (x :: ys, zs) else