jfdm / idris-containers Goto Github PK
View Code? Open in Web Editor NEWVarious data structures for use in the Idris Language.
License: BSD 3-Clause "New" or "Revised" License
Various data structures for use in the Idris Language.
License: BSD 3-Clause "New" or "Revised" License
There is a bit rotted quick check implementation for Idris out there. I do not have time nor knowledge to fix it. In the mean time there is a reasonable setup for testing. This needs expanding and de-duplication of test data and operations where appropriate.
I'm trying to build a basic Idris program that uses this library, and there is a problem:
$ idris --build test.ipkg
Entering directory `.\src'
idris.exe: Erasure/getArity: definition not found for Data.Tree.Empty
CallStack (from HasCallStack):
error, called at src\Idris\Erasure.hs:605:20 in idris-1.3.2-J5ej6IrsDvx8J6Vzd0MiVR:Idris.Erasure
This is the Main.idr
I'm trying to compile, but I don't think that matters:
module Main
import Data.AVL.Set
remove : Ord a => a -> Set a -> Set a
remove x = let to_remove = insert x empty
in flip difference to_remove
example : Set Int
example = fromList [1, 2, 3]
main : IO ()
main = do
putStrLn $ show $ Set.toList $ remove 3 example
The library itself builds and installs fine. Typechecking by itself (from Atom at least) also works.
Hi
I don't understand why equality, as currently defined for sets, would work at all. It seems to only act on the head.
If my point is correct, then how would you go at defining it? In particular, I'm trying to prove that the union of two sets built from lists using fromList
is the same as another set built using fromList
, by means of list permutations, but without much success.
After some improved tests it turns out that the dependently typed AVL tree is broken, and needs fixing.
Would you be up for a Traversable
Instance for Dict
over the values in the dictionary?
I defined it locally as:
Ord a => Functor (Dict a) where
map func x = fromList $ (\(a, b) => (a, func b)) <$> toList x
Ord a => Foldable (Dict a) where
foldr func = foldr $ const func
Ord a => Traversable (Dict a) where
traverse f x = fromList <$> (traverse (\(a, b) => (MkPair a) <$> f b) $ Data.AVL.Dict.toList x)
Several functions impose an Ord
constraint that serves no apparent purpose. It looks like the root of the problem is the height
function, but others that use height
, or that use functions that use height
, are also infected.
Idris is telling me several functions are not total with Idris 1.0. Specifically Data.AVL.Tree.rotLeft
and Data.AVL.Tree.rotRight
. I tried poking around to see if I could fix it, but I'm not well verse enough in Idris and it's been too long since I've thought about AVL trees.
I see no indication that it preserves the ordering invariant. What you probably actually want is a deletion function that also returns an indication of whether the deleted element was previously in the tree.
The current queue implementation does not work properly in a persistent setting. It also doesn't have much in the way of proof behind it. I've opened pull request #10 to add Okasaki-style Banker's queues. They're rather more complicated, so it's quite possible that we should keep the simpler ones as well for the times when they're appropriate.
There is a simple non-dependently typed implementation of RedBlack trees in the repository.
delete
, merge
, update
.Unlike ::
for List
, insert
on Dict
seems to lose information so that I can't prove much about the results.
I wrote an analog of lookup
that uses HasKey
proofs (see below) and now I want to prove...
insertValue: DecEq k => Ord k => (key: k) -> (dict: Dict k v)
-> keyValue key (insert key val dict) found = val
but I don't see how.
keyValue: (key: k) -> (dict: (Dict k v)) -> (pf: HasKey key dict)
-> v
keyValue key (MkDict $ Element t inv) (IsKey (IsKey found)) =
keyValue' key t found
where
keyValue': (key: k) -> (t: Tree k v) -> (found: IsKeyIn key t) -> v
keyValue' key (Node key val _ _) Here = val
keyValue' key (Node not_key val left r) (InRight later) =
keyValue' key r later
keyValue' key (Node not_key val l right) (InLeft later) =
keyValue' key l later
There are two types of AVL tree implementation in this project. The first, is a 'standard' implementation of AVL trees that was taken and adapted from Haskell. The second, uses dependent types to ensure that only balanced trees can be constructed.
There are issues with these implementations:
merge
,split
,remove
,update
.Update
This issue was partially addressed by provision of a dependently typed AVL tree implementation with the invariants separated. However, there is a yet to be diagnosed problem with rotation, it is lossy.
$ idris -v
1.3.3
idris --build containers.ipkg
Type checking ./Data/RedBlack/Tree.idr
./Data/RedBlack/Tree.idr:213:13-38:
|
213 | ins x vx t@(Element (Node _ y _ _ _) _) = insWith x vx t (compare x y)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
When checking right hand side of Data.RedBlack.Tree.ins, insWith with expected type
(c' : Colour ** valid : Bool ** InsTree n c' k v valid)
When checking argument pf to constructor Prelude.Pairs.Element:
Type mismatch between
RBInvariant n underscorePatVar2 True (Node underscorePatVar2 y_shadow underscorePatVar3 underscorePatVar4 underscorePatVar) (Type of underscorePatVar)
and
P (Node underscorePatVar2 y underscorePatVar3 underscorePatVar4 underscorePatVar) (Expected type)
make: *** [lib] Error 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.