[Haskell-cafe] Data polymophism
Phlex at telenet.be
Fri Jun 8 11:23:23 EDT 2007
It seems this message was lost somehow, so i'm trying to send it again
....sorry if it comes up twice on the list !
I have this class which gives a common interface to (UniqueIndex a k)
and (MultiIndex a k) :
class (Show a, Key_ k) => Index_ i a k | i -> k, k -> a where
buildKey :: (a -> k)
insertIndex :: Id -> a -> i -> Maybe i
deleteIndex :: Id -> a -> i -> i
updateIndex :: Id -> a -> a -> i -> Maybe i
updateIndex id oldItem newItem index = insertIndex id newItem $
deleteIndex id oldItem index
Now i need to have these indexes in a list, so i declared that type :
data DbIndex = forall a k i. (Show a, Key_ k, Index_ i a k) => DbIndex i
Up to this point everything is fine, I can create concrete Indexes and
put these different index types in the same list, after wrapping them in
But i don't seem to find a way to get out of this DbIndex type to
actually work on the enclosed index.
for instance, this doesn't work:
liftDbIndex (DbIndex index) fun = DbIndex (fun index)
this doesn't work either :
dbIndexBuildKey (DbIndex index) value = (buildKey index) value
How can i access the enclosed concrete index, via its Index_ class ?
Maybe am I totally on the wrong track ?
Thanks in advance,
More information about the Haskell-Cafe