[Haskell-cafe] serialize an unknown type
Corentin Dupont
corentin.dupont at gmail.com
Wed Oct 24 18:01:58 CEST 2012
I'm trying to get around my problem (still stuck...).
I have really to call a function like this:
triggerEvent :: (Typeable e, Show e, Eq e) => Event e -> EventData e ->
State Game ()
This function simply execute an event given the corresponding data and
change the state of the game.
Now as explained my web framework won't accept random types (like "e") to
be passed around.
So I said to myself "OK, so let's store the events in a list and ask the
gui to just give me the number of the event".
So I have an heterogeneous list of events [EventWrap]:
data EventWrap where
EW :: (Typeable e, Show e, Eq e) => {eventNumber :: Int, event :: Event
e} -> EventWrap
Do you think this solution can lead me somewhere?? I have actually doubts I
can find back my "Event e" from the list because of the implicit forall in
the GADT.....
Thanks,
Corentin
On Wed, Oct 24, 2012 at 3:37 PM, Chris Smith <cdsmith at gmail.com> wrote:
> "Corentin Dupont" <corentin.dupont at gmail.com> wrote:
> > I could ask my user to make his new type an instance of a class as
> suggested by Alberto...
>
> If you are working with unknown types, then your options are: (a)
> constrain to some type class, or (b) have your clients pass in functions to
> operate on the type alongside the values. Actually the first is just a
> special case of the second with syntactic sugar...
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121024/9f3451cd/attachment.htm>
More information about the Haskell-Cafe
mailing list