@@ -17,21 +17,22 @@ Unfortunately this does not work:
1717```
1818❌ -- Type Error -------------------------------------------------- Main.flix
1919
20- >> Impure function declared as pure .
20+ >> Unable to unify the effect formulas: 'IO' and 'Pure' .
2121
22- 1 | def sum(x: Int32, y: Int32): Int32 =
23- ^^^
24- impure function.
22+ 1 |> def sum(x: Int32, y: Int32): Int32 =
23+ 2 |> println(x);
24+ 3 |> println(y);
25+ 4 |> x + y
2526```
2627
27- The problem is that printing is inherently an effectful operation and hence we
28- cannot use it to debug our pure functions! We could make our ` sum ` function have
29- the ` IO ` effect, but that is rarely what we want. Fortunately , Flix has a
28+ The problem is that ` println ` has the ` IO ` . Hence, we cannot use it to for
29+ print debugging inside pure functions. We could make our ` sum ` function have
30+ the ` IO ` effect, but that is rarely what we want. Instead , Flix has a
3031built-in debugging facility that allows us to do print-line debugging.
3132
3233### The ` Debug.dprint ` and ` Debug.dprintln ` Functions
3334
34- Instead, we can write the following :
35+ We can write:
3536
3637``` flix
3738use Debug.dprintln;
@@ -46,6 +47,18 @@ Inside the `sum` function, the `dprintln` has the effect `Debug`, but due to
4647its special nature, the ` Debug ` effect "disappears" once we exit the function,
4748i.e. it is not part of its type and effect signature.
4849
49- We should only use ` dprintln ` and ` dprint ` for debugging.
50+ ### Debugging with Source Locations
5051
51- A future version of Flix will disallow it in production mode.
52+ We can use the special _ debug string interpolator_ to add source locations
53+ to our print statements:
54+
55+ ``` flix
56+ use Debug.dprintln;
57+
58+ def sum(x: Int32, y: Int32): Int32 =
59+ dprintln(d"Hello World!");
60+ x + y
61+ ```
62+
63+ > A longer introduction to ` dprintln ` is available in the
64+ > blog post [ Effect Systems vs Print Debugging: A Pragmatic Solution] ( https://blog.flix.dev/blog/effect-systems-vs-print-debugging/ )
0 commit comments