Hi Daniel,<br>in my game the handlers are supplied by the players as part of little programs that they submit. An haskell interpreter is reading the program code submitted and inserts it in the game.<br>So there is an infinite number of handlers...<br>
I was thinking of hiding the parameters of the handlers like this:<br><span style="font-family:courier new,monospace"><br>data Exp a where<br>
     OnEvent :: EventName -&gt; Exp () -&gt; Exp ()<br>    
getArg :: Exp Int<br>     setArg :: Exp ()<br>     deriving (Show)</span><br><br>Now it should be possible to write the Show instance:<br><span style="font-family:courier new,monospace">instance Show a -&gt; Show (Exp a) where ...</span><br>
<br>You could write a program like this:<br><span style="font-family:courier new,monospace"><br>myProgram :: Exp ()<br>myProgram = do<br>   OnEvent NewPlayer (getArg &gt;&gt;= (\name -&gt; output $ &quot;Hello to player &quot; ++ name))<br>
</span><br><br>But I don&#39;t find it elegant at all: there is no compile time guaranty that the caller will set the argument correctly as you can have with normal function signatures...<br>Best,<br>Corentin<br><br><div class="gmail_quote">
On Sun, Mar 24, 2013 at 6:25 PM, Daniel Trstenjak <span dir="ltr">&lt;<a href="mailto:daniel.trstenjak@gmail.com" target="_blank">daniel.trstenjak@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Hi Corentin,<br>
<div><div class="h5"><br>
&gt; I have a DSL like this:<br>
&gt; data Exp where<br>
&gt;     OnEvent      :: EventName -&gt; (Int -&gt; Exp) -&gt; Exp<br>
&gt; (...)<br>
&gt;<br>
&gt; The &quot;OnEvent&quot; element carries a function (the handler to be called when the<br>
&gt; event happens), and that makes my DSL non showable/serializable.<br>
&gt; How could I fix that? This is a real handicap not to be able to serialize<br>
&gt; the state of my whole application because of that :)<br>
<br>
</div></div>You could have a unique id for your handlers, which might be<br>
an Int or a String and have some kind of registration for the<br>
handlers.<br>
<br>
data Exp where<br>
    OnEvent :: EventName -&gt; HandlerId -&gt; Exp<br>
<br>
type HandlerId = String<br>
type Handler   = (Int -&gt; Exp)<br>
type Handlers  = HashMap HandlerId Handler<br>
<br>
registerHandler :: Handlers -&gt; (HandlerId, Handler) -&gt; Handlers<br>
getHandler      :: Handlers -&gt; HandlerId -&gt; Maybe Handler<br>
<br>
But you have to ensure, that for each application run the same<br>
HandlerId also gets the same Handler.<br>
<br>
<br>
Less flexible but more secure is an ADT for you Handler.<br>
<br>
data Handler = DoThat<br>
             | DoSometingElse<br>
<br>
You can than just pattern match on your handler and don&#39;t need any kind<br>
of registration.<br>
<br>
<br>
But you can go further and define your own little Handler DSL.<br>
<br>
<br>
Greetings,<br>
Daniel<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>