@@ -1,39 +1,6 @@
1module Language.Haskell.Generate
1module Language.Haskell.Generate
6import Language.Haskell.Generate.Base as X
5import Language.Haskell.Generate.Base as X
7import Language.Haskell.Generate.PreludeDef as X
6import Language.Haskell.Generate.PreludeDef as X
10− This library allows you to generate type-correct haskell expressions. To use it, you need to import this module:
12−> import Language.Haskell.Generate
14− This will import the methods for generating haskell expressions and also a list of predefined expressions consisting of functions from the haskell Prelude
15− that you can use to build your own expressions. For example, here is an expression that reads the file 'names':
17−> readNames :: ExpG (IO String)
18−> readNames = readFile' <>$ expr "names"
20− First, look at the type of readNames. @'ExpG'@ is a data type provided by haskell-generate for haskell expressions. We want to generate an expression
21− that returns an IO String, so the type of readNames is @ExpG (IO String)@.
22− @readFile'@ is an expression for the haskell readFile function. You can use almost any Prelude function in your expression by adding an apostrophe to
23− the end of the function name.
24− We use (<>$) to generate a expression that applies 'readFile' to the expression "names". @'expr'@ automagically generates a literal expression.
26− Now that we have an expression to read the @names@ file, we can generate a module with it:
30−> readNamesDecl <- addDecl (Ident "readNames") readNames
31−> return $ Just [exportFun readNamesDecl]
37−> putStrLn $ generateModule myModule "FooBar"