Asking on existential types, i wrote 

>> It is required to organise a table with the key
>>                                         data K = K1 | K2 | K3 ...
>> 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)
>> [...]


I thank  Simon Marlow, Fergus Henderson, Jose Emilio Labra Gayo, 
         Pablo Azero, Koen Claessen, Christian Sievers

for the explanations. I am going to study them. 
Hm ... still try to escape :-)
Maybe, you can tell now simply: 
                   have i a chance to simplify denotations with this?

For, Fergus Henderson  writes

>> to put/extract there the items of different types, say,  'a'  and 
>> ('a','b')  as well.  Is this possible?
>
> Yes.  
> But what do you want to do with the values once you've extracted them?



The particular question is: how to get free of extra constructors that
are used to organise a new type from several types?
Example.
  data Name = Meat | Vegetable | Vine  | ...    deriving(Eq)

  data DMeat      = DMeat      {mName  :: String  -- ,...several fields
                               } 
  data DVegetable = DVegetable { different fields }
  data DVine      = DVine      { different fields }
  ...
- 50 kinds of dishes, each described in individual manner
A program works with these dishes, modifying the values in these 
record fields.
But how to operate with Dinner-s?  
We assume a dinner may consist of arbitrary many dishes.

  type Dinner = [(Name,Dish)]

For this, we have to join the above dish-types to one new type

  data Dish = Meat' DMeat | Vegetable' DVegetable | ... -- 50 items

The new task is:  
  get from the dinner its meat part. If it is absent then put there
  such and such shashlyk.

  fixMeat :: Dinner -> (Dinner, DMeat)
  fixMeat    dn     =
                      case  lookup Meat dn
                      of
                        Just (Meat' d) -> (dn               , d)
                        _              -> ((Meat,Meat' s):dn, s)
                                      where
                                      s = DMeat {mName = "shashlyk"}

We have here the parasitic constructors         Meat', Vine'...
that have to "follow" the initial constructors  Meat , Vine ...,
otherwise we cannot get this all into one table.
And the pattern match in this `case':  Meat' is one of 50 
alternatives - i hope, it could match as fast as for 3 alternatives,
but this is certain exercise for the compiler developers.

With existentials, i hoped to achieve the effect of simplification,
something like          ...
                        Just d -> (dn  , d)
                        _      -> (s:dn, s)
                                    where
                                    s = DMeat {name = "shashlyk"...}
Is this possible?
If there is no chance, i would rather forget of existentials, so far.

Thanks a lot for the help.


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





Reply via email to