Skip to content

Commit 2c7d58c

Browse files
feat: update debugging.md (#263)
1 parent de0f412 commit 2c7d58c

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/debugging.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ We might try something like:
77

88
```flix
99
def sum(x: Int32, y: Int32): Int32 =
10-
println(x);
11-
println(y);
12-
x + y
10+
let result = x + y;
11+
println("The sum of ${x} and ${y} is ${result}");
12+
result
1313
```
1414

1515
Unfortunately this does not work:
@@ -20,27 +20,27 @@ Unfortunately this does not work:
2020
>> Unable to unify the effect formulas: 'IO' and 'Pure'.
2121
2222
1 |> def sum(x: Int32, y: Int32): Int32 =
23-
2 |> println(x);
24-
3 |> println(y);
25-
4 |> x + y
23+
2 |> let result = x + y;
24+
3 |> println("The sum of ${x} and ${y} is ${result}");
25+
4 |> result
2626
```
2727

2828
The problem is that `println` has the `IO`. Hence, we cannot use it to for
2929
print debugging inside pure functions. We could make our `sum` function have
3030
the `IO` effect, but that is rarely what we want. Instead, Flix has a
3131
built-in debugging facility that allows us to do print-line debugging.
3232

33-
### The `Debug.dprint` and `Debug.dprintln` Functions
33+
### The `Debug.dprintln` Function
3434

35-
We can write:
35+
Instead, we can use the `Debug.dprintln` function and write:
3636

3737
```flix
3838
use Debug.dprintln;
3939
4040
def sum(x: Int32, y: Int32): Int32 =
41-
dprintln(x);
42-
dprintln(y);
43-
x + y
41+
let result = x + y;
42+
dprintln("The sum of ${x} and ${y} is ${result}");
43+
result
4444
```
4545

4646
Inside the `sum` function, the `dprintln` has the effect `Debug`, but due to
@@ -56,8 +56,9 @@ to our print statements:
5656
use Debug.dprintln;
5757
5858
def sum(x: Int32, y: Int32): Int32 =
59-
dprintln(d"Hello World!");
60-
x + y
59+
let result = x + y;
60+
dprintln(d"The sum of ${x} and ${y} is ${result}");
61+
result
6162
```
6263

6364
> A longer introduction to `dprintln` is available in the

0 commit comments

Comments
 (0)