Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion errors/CycleInDeclaration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ or to contribute content related to this error.

## Cause

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_.
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_.

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

Expand All @@ -28,9 +28,12 @@ var x = x;

since then `x` would be `undefined`.

Note that cycles can also spring up in much less obvious ways, e.g. if you define one typeclass member using another.

## Fix

- Consider the problem again, keeping PureScript's strict evaluation in mind. How would you solve this problem in JavaScript, for example?
- 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`.
- 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.

## Notes
Expand Down