<div dir="ltr"><div><div><div>Hi,<br></div>it's for the Nomyx game (<a href="http://www.nomyx.net">www.nomyx.net</a>). In this game the players submit pieces of code ("rules") that are written in Haskell.<br></div>I would like to serialize the rules submitted to a Haskell format, to give the possibility to the players <br>to work on their rules offline, to check them with a compiler and store them on Github.<br></div>I would look like:<br><br><pre><code>module MyRules where

  myRule1 :: Rule
  myRule1 = Rule {name = "my rule 1",
                  descr = "this is my rule"
                  code = [c|putStrLn "test"|]
                  }</code></pre><br><div><div>Currently the player is able to submit this module file to Nomyx. Nomyx loads the file through a Haskell interpreter.<br></div><div>Once it's done, the player is able to propose "myRule1" in the game.<br></div><div>But what if the player wants to modify the rule in Nomyx? Then I would like to modify the original file to reflect the changes.<br></div><div><br></div><div>In the example, the field "code" contains the actual code of the rule in Haskell. I use a quasi-quotation because I parse it with an interpreter to validate it.<br></div><div>But otherwise it is is considered as a simple string.<br></div><div>This is why a format in Haskell would suit me (instead of XML or JSON): some of the data I need to serialize is indeed Haskell code.<br></div><div><br></div><div>Hope I was not too obscure :)<br><br></div><div>Best,<br></div><div>C<br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Aug 8, 2015 at 1:15 AM, Donn Cave <span dir="ltr"><<a href="mailto:donn@avvanta.com" target="_blank">donn@avvanta.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">quoth Corentin Dupont <<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>><br>
<span class=""><br>
> I want to do exactly what you would do with a JSON file (read, write), but<br>
> with a data format that would be valid Haskell (instead of valid<br>
> javascript).<br>
<br>
</span>OK, but I think this doesn't do much to clear up the mystery.<br>
<br>
Why valid Haskell?<br>
<br>
That will shed a lot of light on what you really want.  You know<br>
you can write and read any value that supports Read and Show classes,<br>
but there's more valid Haskell that isn't values at all, like the<br>
type declarations in your example.  And the module declaration,<br>
not sure whether that's in any sense a value but I don't think<br>
it's going to support Read or Show.<br>
<br>
The applications I can think of don't need type declarations, and<br>
the module would complicate things at best.<br>
<br>
        Donn<br>
<br>
PS  - if you're happy to simply read and write values, next I think<br>
it would probably be prudent to verify that this scales to whatever<br>
you have in mind, I mean very large values might be more efficiently<br>
processed in some other way.<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>