Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Design help to add imports to a (Java) template (Hilco Wijbenga) ---------------------------------------------------------------------- Message: 1 Date: Mon, 2 Jul 2018 13:03:07 -0700 From: Hilco Wijbenga <hilco.wijbe...@gmail.com> To: Haskell Beginners <beginners@haskell.org> Subject: [Haskell-beginners] Design help to add imports to a (Java) template Message-ID: <cae1poi11mzgxe1uyp95r9w_onhgrn0kyaajsohv6hjvppn7...@mail.gmail.com> Content-Type: text/plain; charset="UTF-8" Hi all, I'm working on a Haskell (Eta) tool to generate Java ADTs. I have the following definitions: data Line = Line Int Text [JavaImport] -- The Int represents the indentation level of this line. data Template = None | One Line | Many [Line] | Template (Reader Configuration Template) I then run it like this (incomplete, I hope you get the idea): main :: IO () main = putStr $ replace (importsGoHereKey `append` "\n") importsAsText templateAsText where config = Configuration (Copyright 2018 "Me") USE_GETTERS point' = javaClassTemplate point importsAsText = runReader (mapReader javaImportsToText (javaImports point')) config templateAsText = runReader (toText tab point') config Essentially, I use the template twice: once to extract the Java imports and once to generate the result Text. Then I replace a magic string in the result Text with the import code. It works but makes me sad. ;-) I will probably pull out the JavaImport list from Line and use something like State to keep track of the necessary imports. (Now that I understand Reader, maybe State is no longer a bridge too far.) My main issue is how to avoid the magic string. I thought about adding an extra entry to Template [something like Imports ((Set JavaImport) -> Text or maybe Template)] but then I don't know how to implement "instance Monoid Template". Similarly if I use something Reader like. Any design advice or ideas would be appreciated. If it's of any help, the full code is at [1] (it's tiny). Any and all comments are welcome, by the way: I'm still a Haskell beginner. Cheers, Hilco [1] https://github.com/hilcode/java-algebraic-data-types ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 121, Issue 1 *****************************************