summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreliaslfox <>2017-08-21 07:28:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-08-21 07:28:00 (GMT)
commit9729ce842d5f31d7431f48012a777218f79942a5 (patch)
tree82a35986d1076f6d9f68ccab3df14d49288e01d6
parenta1d88ed5dfb5570e1b985a8a1fe6ee2f3bcccc6e (diff)
version 0.0.10.00.0.10.0
-rw-r--r--README.md86
-rw-r--r--language-elm.cabal2
2 files changed, 87 insertions, 1 deletions
diff --git a/README.md b/README.md
index bbe0461..a66f31a 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,87 @@
# language-elm
+A haskell library for generating elm source code from an ast.
+
+## Usage
+Install language-elm from stack
+```
+stack install language-elm
+```
+
+Import the libraries
+```haskell
+import Elm.Decleration
+import Elm.Expression
+import Elm.Import
+import Elm.Program
+import Elm.Type
+```
+
+Declare a program type
+```haskell
+program :: Program
+program =
+ Program
+ "Tuple"
+ (Select
+ [ Item "first"
+ , Item "second"
+ , Item "mapFirst"
+ , Item "mapSecond"
+ ])
+ []
+ [ Dec
+ "first"
+ (TApp [TTuple2 (tvar "a1") (tvar "a2"), tvar "a1"])
+ [Tuple2 (var "x") (Under)]
+ (var "x")
+ , Dec
+ "second"
+ (TApp [TTuple2 (tvar "a1") (tvar "a2"), tvar "a2"])
+ [Tuple2 (Under) (var "y")]
+ (var "y")
+ , Dec
+ "mapFirst"
+ (TApp
+ [ TApp [tvar "a", tvar "b"]
+ , TTuple2 (tvar "a") (tvar "a2")
+ , TTuple2 (tvar "b") (tvar "a2")
+ ])
+ [var "func", Tuple2 (var "x") (var "y")]
+ (Tuple2 (App "func" [var "x"]) (var "y"))
+ , Dec
+ "mapSecond"
+ (TApp
+ [ TApp [tvar "a", tvar "b"]
+ , TTuple2 (tvar "a1") (tvar "a")
+ , TTuple2 (tvar "a1") (tvar "b")
+ ])
+ [var "func", Tuple2 (var "x") (var "y")]
+ (Tuple2 (var "x") (App "func" [var "y"]))
+ ]
+```
+
+Then render the program
+
+```haskell
+output :: String
+output = renderProgram program
+```
+
+Which results in the following output
+
+```elm
+module Tuple exposing (first, second, mapFirst, mapSecond)
+
+first :: ((a1, a2)) -> a1
+first (x, _) = x
+
+second :: ((a1, a2)) -> a2
+second (_, y) = y
+
+mapFirst :: (a -> b) -> ((a, a2)) -> ((b, a2))
+mapFirst func (x, y) = (func x, y)
+
+mapSecond :: (a -> b) -> ((a1, a)) -> ((a1, b))
+mapSecond func (x, y) = (x, func y)
+```
+
diff --git a/language-elm.cabal b/language-elm.cabal
index c31ea0f..4051706 100644
--- a/language-elm.cabal
+++ b/language-elm.cabal
@@ -1,5 +1,5 @@
name: language-elm
-version: 0.0.9.0
+version: 0.0.10.0
synopsis: Generate elm code
description: Generate elm code from an ast
homepage: https://github.com/eliaslfox/language-elm#readme