Re: [Haskell-cafe] Serialize to Haskell
Hi Matthew, yes that's exactly that. I want to do exactly what you would do with a JSON file (read, write), but with a data format that would be valid Haskell (instead of valid javascript). On Fri, Aug 7, 2015 at 8:06 PM, Matthew Pickering < matthewtpickering@gmail.com> wrote:
Hi Corentin,
I don't quite understand your question please can you explain a bit more. Do you want to read a valid haskell source file, perform some changes to the file and then print out a valid source file?
I am a bit confused about the bit about turing-completeness.
Matt
On Fri, Aug 7, 2015 at 7:55 PM, Corentin Dupont <corentin.dupont@gmail.com> wrote:
Hello! I'm wondering if it's possible to serialize some data to a format that is valid Haskell. In practice I would read a file like this:
module Foo where
myData :: MyData myData = MyData {name = "foo", descr = "test" ... }
Reading this into a program is easily feasible with Hint, for example. Then the program would modify some data and serialize it back to:
module Foo where
myData :: MyData myData = MyData {name = "bar", descr = "test2" ... }
In practice I think that the format should be a subset of Haskell that is not Turing-complete. A bit like JSON, which is a subset of Javascript but not Turing complete. Is it possible?
Thanks, Corentin
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
quoth Corentin Dupont <corentin.dupont@gmail.com>
I want to do exactly what you would do with a JSON file (read, write), but with a data format that would be valid Haskell (instead of valid javascript).
OK, but I think this doesn't do much to clear up the mystery. Why valid Haskell? That will shed a lot of light on what you really want. You know you can write and read any value that supports Read and Show classes, but there's more valid Haskell that isn't values at all, like the type declarations in your example. And the module declaration, not sure whether that's in any sense a value but I don't think it's going to support Read or Show. The applications I can think of don't need type declarations, and the module would complicate things at best. Donn PS - if you're happy to simply read and write values, next I think it would probably be prudent to verify that this scales to whatever you have in mind, I mean very large values might be more efficiently processed in some other way.
Hi, it's for the Nomyx game (www.nomyx.net). In this game the players submit pieces of code ("rules") that are written in Haskell. I would like to serialize the rules submitted to a Haskell format, to give the possibility to the players to work on their rules offline, to check them with a compiler and store them on Github. I would look like: module MyRules where myRule1 :: Rule myRule1 = Rule {name = "my rule 1", descr = "this is my rule" code = [c|putStrLn "test"|] } Currently the player is able to submit this module file to Nomyx. Nomyx loads the file through a Haskell interpreter. Once it's done, the player is able to propose "myRule1" in the game. 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. 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. But otherwise it is is considered as a simple string. 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. Hope I was not too obscure :) Best, C On Sat, Aug 8, 2015 at 1:15 AM, Donn Cave <donn@avvanta.com> wrote:
quoth Corentin Dupont <corentin.dupont@gmail.com>
I want to do exactly what you would do with a JSON file (read, write), but with a data format that would be valid Haskell (instead of valid javascript).
OK, but I think this doesn't do much to clear up the mystery.
Why valid Haskell?
That will shed a lot of light on what you really want. You know you can write and read any value that supports Read and Show classes, but there's more valid Haskell that isn't values at all, like the type declarations in your example. And the module declaration, not sure whether that's in any sense a value but I don't think it's going to support Read or Show.
The applications I can think of don't need type declarations, and the module would complicate things at best.
Donn
PS - if you're happy to simply read and write values, next I think it would probably be prudent to verify that this scales to whatever you have in mind, I mean very large values might be more efficiently processed in some other way. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Alan Zimmerman and myself have written a library which aims to make these sorts of transformations easy. We are still in the early stages but depending on what exactly you want to do then it might be suitable for your purposes. Looking now on hackage the documentation isn't very good so it might not be obvious how you're meant to use it. https://hackage.haskell.org/package/ghc-exactprint The basic idea is, use one of the parsers from the Parsers module, do a (generic) transformation on the resulting ast, then call `exactPrintWithAnns` on the AST and the resulting annotations. For simple transformations (moving, deletion, renaming) it is sufficient to not modify the annotations. When doing insertions/replacements, you will probably have to modify the annotations in some way to get a sensible output. https://hackage.haskell.org/package/ghc-exactprint-0.3.1/docs/Language-Haske... I don't think I'm quite sure what exactly you want, if you can give a specific use case then it will help me give a better answer. We also hang around in #haskell-refactorer if it is transforming source files that you are interested in. Here is an example of how to use the library to insert a type signature for example. https://github.com/alanz/ghc-exactprint/blob/master/examples/InsertSignature... Happy to answer any more questions.. Matt On Sat, Aug 8, 2015 at 1:04 AM, Corentin Dupont <corentin.dupont@gmail.com> wrote:
Hi Matthew, yes that's exactly that. I want to do exactly what you would do with a JSON file (read, write), but with a data format that would be valid Haskell (instead of valid javascript).
On Fri, Aug 7, 2015 at 8:06 PM, Matthew Pickering <matthewtpickering@gmail.com> wrote:
Hi Corentin,
I don't quite understand your question please can you explain a bit more. Do you want to read a valid haskell source file, perform some changes to the file and then print out a valid source file?
I am a bit confused about the bit about turing-completeness.
Matt
On Fri, Aug 7, 2015 at 7:55 PM, Corentin Dupont <corentin.dupont@gmail.com> wrote:
Hello! I'm wondering if it's possible to serialize some data to a format that is valid Haskell. In practice I would read a file like this:
module Foo where
myData :: MyData myData = MyData {name = "foo", descr = "test" ... }
Reading this into a program is easily feasible with Hint, for example. Then the program would modify some data and serialize it back to:
module Foo where
myData :: MyData myData = MyData {name = "bar", descr = "test2" ... }
In practice I think that the format should be a subset of Haskell that is not Turing-complete. A bit like JSON, which is a subset of Javascript but not Turing complete. Is it possible?
Thanks, Corentin
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
This seems to be what I need! I'll give a look. On Sat, Aug 8, 2015 at 1:24 AM, Matthew Pickering < matthewtpickering@gmail.com> wrote:
Alan Zimmerman and myself have written a library which aims to make these sorts of transformations easy. We are still in the early stages but depending on what exactly you want to do then it might be suitable for your purposes. Looking now on hackage the documentation isn't very good so it might not be obvious how you're meant to use it.
https://hackage.haskell.org/package/ghc-exactprint
The basic idea is, use one of the parsers from the Parsers module, do a (generic) transformation on the resulting ast, then call `exactPrintWithAnns` on the AST and the resulting annotations. For simple transformations (moving, deletion, renaming) it is sufficient to not modify the annotations. When doing insertions/replacements, you will probably have to modify the annotations in some way to get a sensible output.
https://hackage.haskell.org/package/ghc-exactprint-0.3.1/docs/Language-Haske...
I don't think I'm quite sure what exactly you want, if you can give a specific use case then it will help me give a better answer. We also hang around in #haskell-refactorer if it is transforming source files that you are interested in.
Here is an example of how to use the library to insert a type signature for example.
https://github.com/alanz/ghc-exactprint/blob/master/examples/InsertSignature...
Happy to answer any more questions..
Matt
On Sat, Aug 8, 2015 at 1:04 AM, Corentin Dupont <corentin.dupont@gmail.com> wrote:
Hi Matthew, yes that's exactly that. I want to do exactly what you would do with a JSON file (read, write), but with a data format that would be valid Haskell (instead of valid javascript).
On Fri, Aug 7, 2015 at 8:06 PM, Matthew Pickering <matthewtpickering@gmail.com> wrote:
Hi Corentin,
I don't quite understand your question please can you explain a bit more. Do you want to read a valid haskell source file, perform some changes to the file and then print out a valid source file?
I am a bit confused about the bit about turing-completeness.
Matt
On Fri, Aug 7, 2015 at 7:55 PM, Corentin Dupont <corentin.dupont@gmail.com> wrote:
Hello! I'm wondering if it's possible to serialize some data to a format that is valid Haskell. In practice I would read a file like this:
module Foo where
myData :: MyData myData = MyData {name = "foo", descr = "test" ... }
Reading this into a program is easily feasible with Hint, for example. Then the program would modify some data and serialize it back to:
module Foo where
myData :: MyData myData = MyData {name = "bar", descr = "test2" ... }
In practice I think that the format should be a subset of Haskell that is not Turing-complete. A bit like JSON, which is a subset of Javascript but not Turing complete. Is it possible?
Thanks, Corentin
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
The Read and Show instances are exactly for that purpose..... 2015-08-08 1:04 GMT+02:00 Corentin Dupont <corentin.dupont@gmail.com>:
Hi Matthew, yes that's exactly that. I want to do exactly what you would do with a JSON file (read, write), but with a data format that would be valid Haskell (instead of valid javascript).
On Fri, Aug 7, 2015 at 8:06 PM, Matthew Pickering < matthewtpickering@gmail.com> wrote:
Hi Corentin,
I don't quite understand your question please can you explain a bit more. Do you want to read a valid haskell source file, perform some changes to the file and then print out a valid source file?
I am a bit confused about the bit about turing-completeness.
Matt
On Fri, Aug 7, 2015 at 7:55 PM, Corentin Dupont <corentin.dupont@gmail.com> wrote:
Hello! I'm wondering if it's possible to serialize some data to a format that is valid Haskell. In practice I would read a file like this:
module Foo where
myData :: MyData myData = MyData {name = "foo", descr = "test" ... }
Reading this into a program is easily feasible with Hint, for example. Then the program would modify some data and serialize it back to:
module Foo where
myData :: MyData myData = MyData {name = "bar", descr = "test2" ... }
In practice I think that the format should be a subset of Haskell that is not Turing-complete. A bit like JSON, which is a subset of Javascript but not Turing complete. Is it possible?
Thanks, Corentin
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-- Alberto.
participants (4)
-
Alberto G. Corona -
Corentin Dupont -
Donn Cave -
Matthew Pickering