<br><br><div class="gmail_quote">On Sun, Oct 21, 2012 at 8:42 PM, MigMit <span dir="ltr">&lt;<a href="mailto:miguelimo38@yandex.ru" target="_blank">miguelimo38@yandex.ru</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Oh, now I&#39;ve got it.<br>
<br>
First of all, functions of type &quot;IO () -&gt; Event a&quot; are impossible (unless you resort to tricks with unsafePerformIO, which is not what you want to deal with right now). You&#39;ve probably meant something like &quot;IO (Event a)&quot; (at least, that is the type of function which would read &quot;Event a&quot; from file or input stream or something else external).<br>
</blockquote><div><br>Yes, sorry, that&#39;s what I meant.<br>&nbsp;<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Secondly, functions (and values) with parametric types, like &quot;IO (Event a)&quot; require you to provide the type &quot;a&quot; in your code. They won&#39;t take it from somewhere magically. You can take a look at the &quot;read&quot; function in Prelude for example.<br>

<br>
If you really want to store the type information and read it back, you should do it yourself, inventing some representation for your type, writing it to disk, reading back and parsing it. And you can&#39;t do that for all types in existence, so you&#39;ll need to do that for some specific types (and no, instances of Typeable aren&#39;t what you want). And you&#39;ll have to deal with type system, which won&#39;t allow you to just say &quot;hey, let that be whatever type it happens to be, I don&#39;t care&quot;; you&#39;d have to wrap this into one existentially quantified type (or GADT).<br>

<br>
Keep in mind that this is not very Haskell-y. First of all, try to analyse, what this &quot;a&quot; in &quot;Event a&quot; could be. What are the limits here? And don&#39;t say there aren&#39;t any, because if you don&#39;t know anything about the type, you can&#39;t do anything with it. So, maybe you would end up with a finite set of types &mdash; this would simplify matters a lot. Or maybe you&#39;d find out that there are inifinitely many types of events &mdash; but they can be somehow generated with a finite number of constructors &mdash; that would be quite simple as well.<br>

<br>
So, what is the bigger picture here?<br></blockquote><div><br><br>In my application, the user can define the &quot;a&quot;. That&#39;s what makes it difficult. For example, the user can define a new enumerate and submit it to the program (it will be interpreted by hint):<br>
data Choice = You | Me&nbsp; | Them | Everybody deriving (Enum, Typeable, Show, Eq, Bounded)<br>So, the list of types is not known in advance. <br>I could ask my user to make his new type an instance of a class as suggested by Alberto...<br>
<br>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
On Oct 21, 2012, at 9:20 PM, Corentin Dupont &lt;<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>&gt; wrote:<br>
<br>
&gt; Hi,<br>
&gt; Sorry if it was not enough explicit.<br>
&gt; I want to write functions like this:<br>
&gt;<br>
&gt; serialize :: (Show a) =&gt; Event a -&gt; IO ()<br>
&gt; deserialize :: (Read a) =&gt; IO () -&gt; Event a<br>
&gt;<br>
&gt; The functions would write and read the data in a file, storing/retrieving also the type &quot;a&quot; I suppose...<br>
&gt; BR,<br>
&gt; C<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Sun, Oct 21, 2012 at 7:03 PM, MigMit &lt;<a href="mailto:miguelimo38@yandex.ru">miguelimo38@yandex.ru</a>&gt; wrote:<br>
&gt; Seems like nobody really understands what is it that you want to accomplish or what your problem is.<br>
&gt;<br>
&gt; Отправлено с iPhone<br>
&gt;<br>
&gt; 21.10.2012, в 20:39, Corentin Dupont &lt;<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>&gt; написал(а):<br>
&gt;<br>
&gt;&gt; Nobody on this one?<br>
&gt;&gt; Here is a simplified version:<br>
&gt;&gt;<br>
&gt;&gt; data Event a where<br>
&gt;&gt; &nbsp; &nbsp; InputChoice :: &nbsp;a -&gt; Event a<br>
&gt;&gt;<br>
&gt;&gt; How to serialize/deserialize this?<br>
&gt;&gt;<br>
&gt;&gt; Cheers,<br>
&gt;&gt; Corentin<br>
&gt;&gt;<br>
&gt;&gt; On Sat, Oct 20, 2012 at 10:49 PM, Corentin Dupont &lt;<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>&gt; wrote:<br>
&gt;&gt; Hi the list!<br>
&gt;&gt; I have a simple question, how can I serialize/deserialize a structure like this:<br>
&gt;&gt;<br>
&gt;&gt; data InputChoice c &nbsp;deriving Typeable<br>
&gt;&gt; data Event a where<br>
&gt;&gt; &nbsp; &nbsp; InputChoice :: (Eq c, Show c) =&gt; [c] -&gt; c -&gt; Event (InputChoice c)<br>
&gt;&gt; &nbsp;(...)<br>
&gt;&gt;<br>
&gt;&gt; I&#39;d like that the values of type &quot;c&quot; get serialized to a String... That&#39;s the easy part, but for deserializing, oops!<br>
&gt;&gt;<br>
&gt;&gt; Cheers,<br>
&gt;&gt; Corentin<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Haskell-Cafe mailing list<br>
&gt;&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br>
<br>
</div></div></blockquote></div><br>