The language-elm package

[ Tags: bsd3, library, web ] [ Propose Tags ]

Generate elm code from an ast


[Skip to Readme]

Properties

Versions 0.0.1.0, 0.0.2.0, 0.0.3.0, 0.0.4.0, 0.0.5.0, 0.0.6.0, 0.0.7.0, 0.0.8.0, 0.0.9.0, 0.0.10.0, 0.0.10.1, 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3
Dependencies base (>=4.9.1 && <4.10), MissingH (>=1.4.0 && <1.5), mtl (>=2.2.1 && <2.3), pretty (>=1.1.3 && <1.2), protolude (==0.2.*) [details]
License BSD3
Copyright 2017 Elias Lawson-Fox
Author Elias Lawson-Fox
Maintainer eliaslfox@gmail.com
Category Web
Home page https://github.com/eliaslfox/language-elm#readme
Source repository head: git clone https://github.com/eliaslfox/language-elm
Uploaded Wed Sep 13 08:44:24 UTC 2017 by eliaslfox
Distributions NixOS:0.1.0.3
Downloads 443 total (22 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-09-13 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for language-elm-0.1.0.1

[back to package description]

language-elm

A haskell library for generating elm source code from an ast.

Usage

Install language-elm from stack

stack install language-elm

Documentation

Documentation

<!-- Import the libraries ```haskell import Elm.Decleration import Elm.Expression import Elm.Import import Elm.Program import Elm.Type ```

Declare a program type

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

output :: String
output = renderProgram program

Which results in the following output

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)
-->