Skip to content

Commit

Permalink
add more examples #22 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira authored Sep 19, 2024
1 parent 4dd19a1 commit 5194a0a
Show file tree
Hide file tree
Showing 30 changed files with 2,554 additions and 38 deletions.
24 changes: 10 additions & 14 deletions compiler/src/Data/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ module Data.Graph exposing
, Graph
, SCC(..)
, Table
, Vertex
-- , bcc

, buildG
-- , components

, Vertex
-- , bcc
, buildG
-- , components
, dff
, dfs
, edges
Expand All @@ -18,16 +16,14 @@ module Data.Graph exposing
, graphFromEdges
, graphFromEdges_
, indegree
, outdegree
-- , path
-- , reachable
-- , reverseTopSort

, outdegree
-- , path
-- , reachable
-- , reverseTopSort
, scc
, stronglyConnComp
, stronglyConnCompR
-- , topSort

, stronglyConnCompR
-- , topSort
, transposeG
, vertices
)
Expand Down
10 changes: 4 additions & 6 deletions compiler/src/Reporting/Doc.elm
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ module Reporting.Doc exposing
, fromPackage
, fromVersion
, green
, hang
-- , hcat

, hang
-- , hcat
, hsep
, indent
, intToOrdinal
, join
, link
-- , magenta

, link
-- , magenta
, makeLink
, makeNakedLink
, moreArgs
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/Reporting/Render/Type.elm
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ tuple : D.Doc -> D.Doc -> List D.Doc -> D.Doc
tuple a b cs =
let
entries =
List.interweave (D.fromChars "(" :: List.repeat (List.length (b :: cs)) (D.fromChars ",")) (a :: b :: cs)
|> List.intersperse (D.fromChars " ")
List.interweave (D.fromChars "( " :: List.repeat (List.length (b :: cs)) (D.fromChars ", ")) (a :: b :: cs)
in
D.align <| D.sep [ D.cat entries, D.fromChars ")" ]

Expand Down
7 changes: 5 additions & 2 deletions examples/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/file": "1.0.5",
"elm/html": "1.0.0",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"elm/random": "1.0.0",
"elm/svg": "1.0.1",
"elm/time": "1.0.0"
"elm/time": "1.0.0",
"elm-explorations/linear-algebra": "1.0.3",
"elm-explorations/webgl": "1.1.3",
"evancz/elm-playground": "1.0.3"
},
"indirect": {
"elm/bytes": "1.0.8",
"elm/file": "1.0.5",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3"
}
Expand Down
27 changes: 27 additions & 0 deletions examples/src/Animation.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Animation exposing (main)

-- Create animations that spin, wave, and zig-zag.
-- This one is a little red wagon bumping along a dirt road.
--
-- Learn more about the playground here:
-- https://package.elm-lang.org/packages/evancz/elm-playground/latest/
--

import Playground exposing (..)


main =
animation view


view time =
[ octagon darkGray 36
|> moveLeft 100
|> rotate (spin 3 time)
, octagon darkGray 36
|> moveRight 100
|> rotate (spin 3 time)
, rectangle red 300 80
|> moveUp (wave 50 54 2 time)
|> rotate (zigzag -2 2 8 time)
]
90 changes: 90 additions & 0 deletions examples/src/Book.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
module Book exposing (main)

-- Make a GET request to load a book called "Public Opinion"
--
-- Read how it works:
-- https://guide.elm-lang.org/effects/http.html
--

import Browser
import Html exposing (Html, pre, text)
import Http



-- MAIN


main =
Browser.element
{ init = init
, update = update
, subscriptions = subscriptions
, view = view
}



-- MODEL


type Model
= Failure
| Loading
| Success String


init : () -> ( Model, Cmd Msg )
init _ =
( Loading
, Http.get
{ url = "https://elm-lang.org/assets/public-opinion.txt"
, expect = Http.expectString GotText
}
)



-- UPDATE


type Msg
= GotText (Result Http.Error String)


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
GotText result ->
case result of
Ok fullText ->
( Success fullText, Cmd.none )

Err _ ->
( Failure, Cmd.none )



-- SUBSCRIPTIONS


subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none



-- VIEW


view : Model -> Html Msg
view model =
case model of
Failure ->
text "I was unable to load your book."

Loading ->
text "Loading..."

Success fullText ->
pre [] [ text fullText ]
Loading

0 comments on commit 5194a0a

Please sign in to comment.