Hello everyone,
I've been banging my head against my desk a bit so I figured it's time
to ask for help :-)
I'm writing an application that persists data to disk. The hard stuff
is pretty much done (binary serialisation, etc...) The big stumbling
block is that I want users to be able to define their own schemas. This
means that the keys for a data store may be Integer, Strings, etc...
I have a BTreeIndex type:
data BTreeIndex a b = Branch { parentBT :: !BlockPtr,
keysBT :: ![a],
kidsBT :: ![BlockPtr] }
| Leaf { parentBT :: !BlockPtr,
valsBT :: !(LeafMap a b),
prevBT :: !PrevLeaf,
nextBT :: !NextLeaf }
type IdxPS = BTreeIndex PackedString BlockPtr
type IdxInt = BTreeIndex Integer BlockPtr
When a user queries I have to read the input from IO and then somehow
cast the key/index type without angering the type checker. If I omit
the following function I get the ominous "Ambiguous type variable a..."
error. If I use it I get a complaint that the checker was expecting an
Integer rather than a PackedString.
coerceIndex f (Schema _ SInt SPtr _) (r,hdl,o,hdr) = f
(r::IdxInt,hdl,o,hdr)
coerceIndex f (Schema _ SStr SPtr _) (r,hdl,o,hdr) = f
(r::IdxPS,hdl,o,hdr)
Where f is a curried select function (e.g. selectAll, selectByKey,
etc...) waiting for the final tuple containing the index and other
miscellanea that is needed to read the data.
I'm hopelessly lost and I assume that the many brilliant minds on this
list will chuckle, pat me on the head and tell me what I've been doing
wrong.
Thanks for your time guys,
Scott
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe