| 1 | <h2>Comments</h2> |
| 2 | <pre><code>-- Single line comment |
| 3 | {- Multi-line |
| 4 | comment -}</code></pre> |
| 5 | |
| 6 | <h2>Strings and characters</h2> |
| 7 | <pre><code>'a' |
| 8 | '\n' |
| 9 | '\x03' |
| 10 | "foo \" bar" |
| 11 | """ |
| 12 | "multiline strings" are also |
| 13 | supported! |
| 14 | """</code></pre> |
| 15 | |
| 16 | <h2>Full example</h2> |
| 17 | <pre><code>module Main exposing (..) |
| 18 | |
| 19 | import Html exposing (Html) |
| 20 | import Svg exposing (..) |
| 21 | import Svg.Attributes exposing (..) |
| 22 | import Time exposing (Time, second) |
| 23 | |
| 24 | |
| 25 | main = |
| 26 | Html.program |
| 27 | { init = init |
| 28 | , view = view |
| 29 | , update = update |
| 30 | , subscriptions = subscriptions |
| 31 | } |
| 32 | |
| 33 | |
| 34 | |
| 35 | -- MODEL |
| 36 | |
| 37 | |
| 38 | type alias Model = |
| 39 | Time |
| 40 | |
| 41 | |
| 42 | init : ( Model, Cmd Msg ) |
| 43 | init = |
| 44 | ( 0, Cmd.none ) |
| 45 | |
| 46 | |
| 47 | |
| 48 | -- UPDATE |
| 49 | |
| 50 | |
| 51 | type Msg |
| 52 | = Tick Time |
| 53 | |
| 54 | |
| 55 | update : Msg -> Model -> ( Model, Cmd Msg ) |
| 56 | update msg model = |
| 57 | case msg of |
| 58 | Tick newTime -> |
| 59 | ( newTime, Cmd.none ) |
| 60 | |
| 61 | |
| 62 | |
| 63 | -- SUBSCRIPTIONS |
| 64 | |
| 65 | |
| 66 | subscriptions : Model -> Sub Msg |
| 67 | subscriptions model = |
| 68 | Time.every second (\time -> Tick time) |
| 69 | |
| 70 | |
| 71 | |
| 72 | -- VIEW |
| 73 | |
| 74 | |
| 75 | view : Model -> Html Msg |
| 76 | view model = |
| 77 | let |
| 78 | angle = |
| 79 | turns (Time.inMinutes model) |
| 80 | |
| 81 | handX = |
| 82 | toString (50 + 40 * cos angle) |
| 83 | |
| 84 | handY = |
| 85 | toString (50 + 40 * sin angle) |
| 86 | in |
| 87 | svg [ viewBox "0 0 100 100", width "300px" ] |
| 88 | [ circle [ cx "50", cy "50", r "45", fill "#0B79CE" ] [] |
| 89 | , line [ x1 "50", y1 "50", x2 handX, y2 handY, stroke "#023963" ] [] |
| 90 | ] |
| 91 | </code></pre> |