@@ -7,9 +7,9 @@ We might try something like:
77
88``` flix
99def 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
1515Unfortunately this does not work:
@@ -20,27 +20,27 @@ Unfortunately this does not work:
2020>> Unable to unify the effect formulas: 'IO' and 'Pure'.
2121
22221 |> 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
2828The problem is that ` println ` has the ` IO ` . Hence, we cannot use it to for
2929print debugging inside pure functions. We could make our ` sum ` function have
3030the ` IO ` effect, but that is rarely what we want. Instead, Flix has a
3131built-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
3838use Debug.dprintln;
3939
4040def 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
4646Inside the ` sum ` function, the ` dprintln ` has the effect ` Debug ` , but due to
@@ -56,8 +56,9 @@ to our print statements:
5656use Debug.dprintln;
5757
5858def 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