"S.D.Mechveliani" wrote:
> 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.

I'm not sure if this is a real world problem, or just a for-instance.
(You never know! :) Anyway, I can see that fundamental issue that you
want to resolve is how to store various types of data into a single
list. The issue of figuring out the type of each element is is resolved
by the `Name' stored with each element. I don't know much yet about
existential types, but I would think that you would still have to have
some function or something that relates `Name's to particular types.

But my real point in replying to this message is to see if you actually
need a multi-type list. Do you really *need* to have separate types for
DMeat, DVine, etc.? For example, instead of having:

  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
  data Dish = Meat' DMeat | Vegetable' DVegetable | ... -- 50 items

would it be possible to use:

  data Dish = DMeat {mName :: String, ...}
    | DVegetable {...}
    | DVine {...}
    | ...

This would eliminate the need to have a multi-type list, for this
particular example anyway.

- Michael Hobbs


Reply via email to