travitch / persistent-vector

Persistent vectors for Haskell based on array mapped tries
BSD 3-Clause "New" or "Revised" License
27 stars 4 forks source link

Get rid of extra indirections (WIP) #25

Open treeowl opened 4 years ago

treeowl commented 4 years ago

Setting out to implement the ideas in #12.

treeowl commented 4 years ago

A couple thoughts:

  1. I think I actually want to work mostly with UnliftedArray# rather than UnliftedArray. So I probably want a module providing relatively user-friendly operations on UnliftedArray# (using Int rather than Int#, using ST with Box rather than explicit state-token passing, etc).

  2. 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.

treeowl commented 4 years ago

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#.

treeowl commented 4 years ago

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.

treeowl commented 4 years ago

Yeah, I think I'm going with the first idea. It sucks, but at least I know how to make it work.