Skip to content

Commit cf2d876

Browse files
linearrayhdgarrood
authored andcommitted
Expand on CycleInDeclaration and fixes (#241)
1 parent 16449d8 commit cf2d876

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

errors/CycleInDeclaration.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ or to contribute content related to this error.
1818

1919
## Cause
2020

21-
This error occurs when a value refers to itself, or another value in the same binding group, at a point where such a reference would be unavailable due to _strict evaluation_.
21+
This error occurs when a value refers to itself, or another value in the same binding group, at a point where such a reference would be unavailable because of _strict evaluation_.
2222

2323
In the example above, it would be incorrect to generate the JavaScript
2424

@@ -28,9 +28,12 @@ var x = x;
2828

2929
since then `x` would be `undefined`.
3030

31+
Note that cycles can also spring up in much less obvious ways, e.g. if you define one typeclass member using another.
32+
3133
## Fix
3234

3335
- Consider the problem again, keeping PureScript's strict evaluation in mind. How would you solve this problem in JavaScript, for example?
36+
- Sometimes you can break the cycle by strategically using eta expansion (`\x -> f x` instead of `f`) or using do-notation, which will introduce a function to the same effect because of `bind`.
3437
- You might be able to make use of the `Control.Lazy` module, and the [`fix`](https://pursuit.purescript.org/packages/purescript-control/4.1.0/docs/Control.Lazy#v:fix) function in particular.
3538

3639
## Notes

0 commit comments

Comments
 (0)