First, a tl;dr: Is it possible to prove the ordering of the data inside a binary search tree inside the definition of the data structure, where the data is a generic Ord? If it is possible (and I assume it is since it's possible with refinement types, which are arguably weaker than dependent types), what would be the right way of doing it?
Now, for the whole story: I've been working on this project for some time now, it's supposed to be a part of my bachelor thesis where I'm comparing Liquid Haskell to Idris, but I'm struggling to understand how exactly am I supposed to enforce what seems to be a simple boolean test inside the data structure of a tree. Also,I'm not sure it'll make a difference but I'm using Idris 1.
For starters, I'm trying to do something like I was able to do following the Liquid Haskell tutorial, where with refinement types I can enforce the ordering of a binary search tree inside the data structure with simple boolean conditions. A working code can be found here:
https://github.com/LucasTornai/pgc-ufabc/blob/main/haskell-structures/MyBST.hsThat being said, when trying to apply the same rules to Idris, I first seem to have fallen in a trap with "Data.So", where I couldn't manage to prove what I wanted with it. A non-working code sample can be found here, where I manage to compile it, but the ordering rule is able to be broken in the insert function, where I can add bigger numbers than the root in the left side and vice-versa (the wrongInsert function don't prevent the compilation and actually works):
https://github.com/LucasTornai/pgc-ufabc/blob/main/idris-structures/MyBST.idr
After looking in a lot of places, what I thought was the most helpful to get where I was wanting to get was this conversation in the mailing list
https://groups.google.com/g/idris-lang/c/qujHxNuZjZg/m/ji5t_qufAwAJ, but it has a problem I find with most ways to prove thins I'm finding for Idris: it's always using "Nat". In my definition of a binary search tree, I wanted to prove the ordering of the data for any Ord, but I fail to understand what's the missing step from the Nat to a more generic Ord to write this kind of proof.
Also, I'm not sure the way I'm approaching it is right, because I want the proof to be contained inside the data structure, and if you checked the Idris code I wrote, I'm using a dependent tuple where I have a simple tree, and together with it the definition of a BST, which is basically the ordering. Checking this repo I found which seems to have good implementations (and also helped me to learn a lot about Idris):
https://github.com/jfdm/idris-containers, I've seem the BST implementation is also not made the way I want it to be done (they enforce the ordering in the functions, not in the data structure itself), so it makes me doubt what I'm doing a bit.
Having the confirmation that it can be done would already be good, but if so, can someone help to show me how exactly can I enforce this kind of boolean proof inside a data structure? (Not necessarily a BST).