Skip to content

Commit

Permalink
Update output numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCVanB committed Aug 31, 2022
1 parent 3c78843 commit 63cd966
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
28 changes: 13 additions & 15 deletions example_complex.roc
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
#!/usr/bin/env roc

app "example_complex"
packages { pf: "./roc/examples/interactive/cli-platform/main.roc" }
imports [ pf.Stdout.{ line }, pf.Task.{ await }, Random ]
provides [ main ] to pf

packages { pf: "roc/examples/interactive/cli-platform/main.roc" }
imports [pf.Stdout.{ line }, pf.Task.{ await }, Random]
provides [main] to pf

main =

a = point (Random.seed 36)
b = a |> Random.next point

_ <- await (line (Num.toStr a.value.x |> \s -> "a.x == 24 == \(s)"))
_ <- await (line (Num.toStr a.value.y |> \s -> "a.y == 37 == \(s)"))
_ <- await (line (Num.toStr a.value.z |> \s -> "a.z == 61 == \(s)"))
_ <- await (line (Num.toStr a.value.t |> \s -> "a.t == -47 == \(s)"))
_ <- await (line (Num.toStr b.value.x |> \s -> "b.x == 90 == \(s)"))
_ <- await (line (Num.toStr b.value.y |> \s -> "b.y == -100 == \(s)"))
_ <- await (line (Num.toStr b.value.z |> \s -> "b.z == 44 == \(s)"))
_ <- await (line (Num.toStr b.value.t |> \s -> "b.t == 6 == \(s)"))
_ <- await (line (Num.toStr a.value.x |> \s -> "a.x == -59 == \(s)"))
_ <- await (line (Num.toStr a.value.y |> \s -> "a.y == -62 == \(s)"))
_ <- await (line (Num.toStr a.value.z |> \s -> "a.z == -64 == \(s)"))
_ <- await (line (Num.toStr a.value.t |> \s -> "a.t == 4 == \(s)"))
_ <- await (line (Num.toStr b.value.x |> \s -> "b.x == 82 == \(s)"))
_ <- await (line (Num.toStr b.value.y |> \s -> "b.y == 78 == \(s)"))
_ <- await (line (Num.toStr b.value.z |> \s -> "b.z == -64 == \(s)"))
_ <- await (line (Num.toStr b.value.t |> \s -> "b.t == -20 == \(s)"))
line "These values will be the same on every run, because we use a constant seed."


# Complex `Generator`s can be created by chaining primitive `Generator`s.
Point a : { x : a, y : a, z : a, t : a }
point : Random.Generator U32 (Point I32)
point : Random.Generator (Point I32) (Random.State U32)
point = \state ->
min = -100
max = 100
Expand All @@ -38,5 +35,6 @@ point = \state ->
z = Random.next y i
# `Random.next` pairs nicely with the pipe operator (equivalent to `Random.step z.seed i`).
t = z |> Random.next i

# Return a record with `.seed` and `.value` for compatibility.
{ value: { x: x.value, y: y.value, z: z.value, t: t.value }, state: t.state }
4 changes: 2 additions & 2 deletions example_simple.roc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ main =
x = int state # x == { value: 9, state: { value: -60952905, ... } }
y = x |> Random.next int # y == { value: 61, state: { value: 1561666408, ... } }

_ <- await (line (Num.toStr x.value |> \s -> "x: \(s)")) # This will print `x: 9`.
_ <- await (line (Num.toStr y.value |> \s -> "y: \(s)")) # This will print `x: 61`.
_ <- await (line (Num.toStr x.value |> \s -> "x: \(s)")) # This will print `x: 74`.
_ <- await (line (Num.toStr y.value |> \s -> "y: \(s)")) # This will print `x: 96`.
line "These values will be the same on every run, because we use a constant seed (42)."

0 comments on commit 63cd966

Please sign in to comment.