Who could please, explain a bit existential types?

It is required to organise a table with the key

  data K = K1 | K2 | K3  {- ... -}   deriving(Eq,Ord,Enum)

to put/extract there the items of different types, say,  'a'  and 
('a','b')  as well.  Is this possible?

Understanding nothing in this subject, i tried

  data KTab = forall a. KT (FiniteMap K a)

  f :: KTab -> KTab 
  f    (KT t) = case  addToFM t K1 'a'  of
                                 t' -> KT (addToFM t' K2 ('a','b'))

And this does not compile. Then, try

  class Tab t k  where  lkp  :: t a -> k -> Maybe a
                        addT :: t a -> k -> a -> t a

  instance Tab KTab K  where  lkp (KT t) k = lookupFM t k
  ...

Also rejected. How to handle with this?

Thank you in advance.


------------------
Sergey Mechveliani
[EMAIL PROTECTED]







Reply via email to