Skip to content

Commit

Permalink
Merge pull request #176 from roc-lang/syntax-update
Browse files Browse the repository at this point in the history
Header syntax update
  • Loading branch information
Anton-4 authored May 3, 2024
2 parents ac1ea71 + 507a0c6 commit 004c23a
Show file tree
Hide file tree
Showing 27 changed files with 133 additions and 180 deletions.
13 changes: 5 additions & 8 deletions examples/Arithmetic/main.roc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
app "arithmetic"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }
imports [
pf.Stdout,
pf.Task,
pf.Arg,
]
provides [main] to pf
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }

import pf.Stdout
import pf.Task
import pf.Arg

TaskErrors : [InvalidArg, InvalidNumStr]

Expand Down
4 changes: 1 addition & 3 deletions examples/BasicDict/BasicDict.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
interface BasicDict
exposes []
imports []
module []

# the dictionary type is: Dict key value
# Both key and value are type variables
Expand Down
21 changes: 9 additions & 12 deletions examples/CommandLineArgs/main.roc
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# Run with `roc ./examples/CommandLineArgs/main.roc -- examples/CommandLineArgs/input.txt`
app "command-line-args"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}
imports [
pf.Stdout,
pf.File,
pf.Path,
pf.Task,
pf.Arg,
]
provides [main] to pf
app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}

import pf.Stdout
import pf.File
import pf.Path
import pf.Task
import pf.Arg

main =
finalTask =
Expand Down
5 changes: 1 addition & 4 deletions examples/DotNetPlatform/main.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
app "dotnetapp"
packages { platform: "./platform/main.roc" }
imports []
provides [main] to platform
app [main] { platform: platform "./platform/main.roc" }

main = "Hi from roc! (in a .NET platform) 🔥🦅🔥"
22 changes: 8 additions & 14 deletions examples/EncodeDecode/main.roc
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
app "example"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.7.0/xuaMzXRVG_SEhOFZucS3iBozlRdObWsfKaYZMHVE_q0.tar.br",
}
imports [
pf.Stdout.{ line },
pf.Task,
json.Core.{ json },
Decode.{ Decoder, DecoderFormatting, DecodeResult, DecodeError },
Encode.{ Encoder, EncoderFormatting },
]
provides [main] to pf

app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
json: "https://github.com/Anton-4/roc-json/releases/download/patch26/L5rrSODQWRomTzNf3qeZmrTI6CUe5dqW6rd2m2Pp7Nc.tar.br",
}

import pf.Task
import json.Core exposing [json]
import pf.Stdout
### start snippet impl

ItemKind := [
Expand Down
8 changes: 4 additions & 4 deletions examples/FizzBuzz/main.roc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
app "fizz-buzz"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }
imports [pf.Stdout, pf.Task]
provides [main] to pf
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }

import pf.Stdout
import pf.Task

main =
List.range { start: At 1, end: At 100 }
Expand Down
5 changes: 1 addition & 4 deletions examples/GoPlatform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ $ roc build --bundle .tar.br platform/main.roc

4. Now you can use the platform from inside a Roc file with:
```roc
app "goUsingRocApp"
packages { pf: "YOUR_URL" }
imports []
provides [main] to pf
app [goUsingRocApp] { pf: platform "YOUR_URL" }
```

When running with a platform from a URL, the `--prebuilt-platform` flag is not needed.
Expand Down
5 changes: 1 addition & 4 deletions examples/GoPlatform/main.roc
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
app "rocLovesGo"
packages { pf: "platform/main.roc" }
imports []
provides [main] to pf
app [main] { pf: platform "platform/main.roc" }

# Can segfault on some Ubuntu 20.04 CI machines, see #164.
main = "Roc <3 Go!\n"
16 changes: 7 additions & 9 deletions examples/GraphTraversal/Graph.roc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
## using an [adjacency list](https://en.wikipedia.org/wiki/Adjacency_list)
## and exposes functions for working with graphs, such as creating one from a list and
## performing a depth-first or breadth-first search.
interface Graph
exposes [
Graph,
fromList,
fromDict,
dfs,
bfs,
]
imports []
module [
Graph,
fromList,
fromDict,
dfs,
bfs,
]

## Graph type representing a graph as a dictionary of adjacency lists,
## where each key is a vertex and each value is a list of its adjacent vertices.
Expand Down
8 changes: 4 additions & 4 deletions examples/HelloWorld/main.roc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
app "hello-world"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }
imports [pf.Stdout, pf.Task]
provides [main] to pf
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }

import pf.Stdout
import pf.Task

main =
Stdout.line! "Hello, World!"
8 changes: 3 additions & 5 deletions examples/IngestFiles/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Ingest Files

Statically importing files as a `Str` or a `List U8`:
Statically importing files as a `Str` or a `List U8` (list of bytes):

```roc
imports [
"some-file" as someStr : Str,
"some-file" as someBytes : List U8,
]
import "some-file" as someStr : Str
import "some-file" as someBytes : List U8
```

## Code
Expand Down
13 changes: 5 additions & 8 deletions examples/IngestFiles/main.roc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
app "ingested-file"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }
imports [
pf.Stdout,
pf.Task,
"sample.txt" as sample : Str,
]
provides [main] to pf
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }

import pf.Stdout
import pf.Task
import "sample.txt" as sample : Str

main =
Stdout.line! "$(sample)"
21 changes: 9 additions & 12 deletions examples/Json/main.roc
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
app "json-basic"
packages {
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.7.0/xuaMzXRVG_SEhOFZucS3iBozlRdObWsfKaYZMHVE_q0.tar.br",
}
imports [
cli.Stdout,
cli.Task,
json.Core.{ jsonWithOptions },
Decode.{ DecodeResult, fromBytesPartial },
]
provides [main] to cli
app [main] {
cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
json: "https://github.com/Anton-4/roc-json/releases/download/patch26/L5rrSODQWRomTzNf3qeZmrTI6CUe5dqW6rd2m2Pp7Nc.tar.br",
}

import cli.Stdout
import cli.Task
import json.Core exposing [jsonWithOptions]
import Decode exposing [fromBytesPartial]

main =
requestBody = Str.toUtf8 "{\"Image\":{\"Animated\":false,\"Height\":600,\"Ids\":[116,943,234,38793],\"Thumbnail\":{\"Height\":125,\"Url\":\"http:\\/\\/www.example.com\\/image\\/481989943\",\"Width\":100},\"Title\":\"View from 15th Floor\",\"Width\":800}}"
Expand Down
11 changes: 4 additions & 7 deletions examples/LeastSquares/main.roc
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
app "example"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }
imports [
pf.Stdout,
pf.Task,
]
provides [main] to pf
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }

import pf.Stdout
import pf.Task

main =
nStr = Num.toStr (leastSquareDifference {})
Expand Down
5 changes: 2 additions & 3 deletions examples/MultipleRocFiles/Hello.roc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
interface Hello
module
# Only what's in 'exposes' is accessible to other modules
exposes [hello]
imports []
[hello]

hello : Str -> Str
hello = \name ->
Expand Down
2 changes: 1 addition & 1 deletion examples/MultipleRocFiles/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Multiple Roc Files

You can use Interface modules to organize your code into multiple files.
You can use modules to organize your code into multiple files.

## Code

Expand Down
10 changes: 5 additions & 5 deletions examples/MultipleRocFiles/main.roc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
app "interface-modules"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }
# we import Stdout from the platform and the Hello interface from the Hello.roc file
imports [pf.Stdout, pf.Task, Hello]
provides [main] to pf
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }

import pf.Stdout
import pf.Task
import Hello

main =
Stdout.line! (Hello.hello "World")
21 changes: 9 additions & 12 deletions examples/Parser/main.roc
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
app "parser-basic"
packages {
cli: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.5.2/9VrPjwfQQ1QeSL3CfmWr2Pr9DESdDIXy97pwpuq84Ck.tar.br",
}
imports [
cli.Stdout,
cli.Task,
parser.Core.{ Parser, many, oneOf, map },
parser.String.{ parseStr, codeunit, anyCodeunit },
]
provides [main] to cli
app [main] {
cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.5.2/9VrPjwfQQ1QeSL3CfmWr2Pr9DESdDIXy97pwpuq84Ck.tar.br",
}

import cli.Stdout
import cli.Task
import parser.Core exposing [Parser, many, oneOf, map]
import parser.String exposing [parseStr, codeunit, anyCodeunit]

main =
many letterParser
Expand Down
4 changes: 1 addition & 3 deletions examples/PatternMatching/PatternMatching.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
interface PatternMatching
exposes []
imports []
module []

# Match an empty list
expect
Expand Down
19 changes: 8 additions & 11 deletions examples/RandomNumbers/main.roc
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
app "random-numbers"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
rand: "https://github.com/lukewilliamboswell/roc-random/releases/download/0.0.1/x_XwrgehcQI4KukXligrAkWTavqDAdE5jGamURpaX-M.tar.br",
}
imports [
pf.Stdout,
pf.Task,
rand.Random,
]
provides [main] to pf
app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
rand: "https://github.com/lukewilliamboswell/roc-random/releases/download/0.0.1/x_XwrgehcQI4KukXligrAkWTavqDAdE5jGamURpaX-M.tar.br",
}

import pf.Stdout
import pf.Task
import rand.Random

# Print a list of 10 random numbers in the range 25-75 inclusive.
main =
Expand Down
14 changes: 6 additions & 8 deletions examples/RecordBuilder/IDCounter.roc
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
interface IDCounter
exposes [
IDCount,
initIDCount,
incID,
extractState,
]
imports []
module [
IDCount,
initIDCount,
incID,
extractState,
]

ID : U32

Expand Down
14 changes: 8 additions & 6 deletions examples/TaskLoop/main.roc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
app "task-usage"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}
imports [pf.Stdin, pf.Stdout, pf.Stderr, pf.Task.{ Task }]
provides [main] to pf
app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}

import pf.Stdin
import pf.Stdout
import pf.Stderr
import pf.Task exposing [Task]

main = run |> Task.onErr printErr

Expand Down
22 changes: 14 additions & 8 deletions examples/Tasks/main.roc
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
app "task-usage"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}
imports [pf.Stdout, pf.Stderr, pf.Arg, pf.Env, pf.Http, pf.Dir, pf.Utc, pf.File, pf.Path.{ Path }, pf.Task.{ Task }]
provides [main] to pf
app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}

import pf.Stdout
import pf.Stderr
import pf.Arg
import pf.Env
import pf.Http
import pf.Dir
import pf.Utc
import pf.File
import pf.Path exposing [Path]
import pf.Task exposing [Task]

main : Task {} _
main = run |> Task.onErr handleErr
Expand All @@ -27,11 +35,9 @@ run =
# Fetch the provided url using HTTP
strHTML = fetchHtml! url
Stdout.line! "Saving url HTML to $(Path.display outputPath)..."

# Write HTML string to a file
File.writeUtf8 outputPath strHTML
|> Task.onErr! \_ -> Task.err (FailedToWriteFile outputPath)

# Print contents of current working directory
listCwdContent
|> Task.map \dirContents ->
Expand Down
8 changes: 3 additions & 5 deletions examples/TowersOfHanoi/Hanoi.roc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
interface Hanoi
exposes [
hanoi,
]
imports []
module [
hanoi,
]

## Solves the Tower of Hanoi problem using recursion. Returns a list of moves
## which represent the solution.
Expand Down
Loading

0 comments on commit 004c23a

Please sign in to comment.