Get rid of extra indirections (WIP)
Setting out to implement the ideas in #12.
-
Store a
Vector_in the root node instead of anArrayofVector_s. This simplifies almost everything and should make the code smaller. This seems especially important for folds, which we generally want to inline. But we get one extra indirection per vector until we actually unlift everything. -
Make
Vector_a GADT. This lets us use the type system to enforce the height balance invariant. Ultimately, this is going to have to look different, but I think it's not a bad first step. -
Add a validity test to check the rest of the data structure invariants.
A couple thoughts:
-
I think I actually want to work mostly with
UnliftedArray#rather thanUnliftedArray. So I probably want a module providing relatively user-friendly operations onUnliftedArray#(usingIntrather thanInt#, usingSTwithBoxrather than explicit state-token passing, etc). -
To make things as backwards compatible as possible, use a data family rather than an injective type family. But we want to discard those newtype constructors with as little fuss as possible. I'm developing a pretty decent sense of how I think I want that to work.
There is another alternative to working mostly with UnliftedArray#, I think. The idea is to generalize Array and UnliftedArray to a unified type. This will be annoying, but it might shift the burden of ugliness into a simpler space.
-- Keep the kind open to support unboxed arrays?
data L
data U
type family Blob (l :: Type) (a :: Type) :: TYPE 'UnliftedRep
type instance Blob L a = Array# a
type instance Blob U a = UnliftedArray# (Unlifted a)
data Array (l :: Type) (a :: Type) = Array (Blob l a)
What's this do? It lets us yank an Array out of an Array 'U without having to determine whether it's actually an Array# or an UnliftedArray#.
No, that second thing isn't quite right. We need to add in an assumption that an Array U holds an Array x... hmm... Might not work out.
Yeah, I think I'm going with the first idea. It sucks, but at least I know how to make it work.