Current compiler behavior
The PureScript compiler rejects unification that would make a row variable refer to itself. When a row variable is unified with a row that contains that same variable via a recursive definition, the occurs check fails and the compiler reports an infinite type / occurs check error instead of inferring a type.
Confirmed facts
- Row polymorphism is implemented with row constraints and structural row unification. Recursive type synonyms and data types are expanded during unification.
- The unification engine applies an occurs check to rows. A row variable cannot be solved to a row that mentions itself.
- The need for extensible records is supported for non-recursive uses of row variables. The limitation is specific to recursive boundaries where the row variable is unified with a row containing itself.
Likely explanation
In a recursive definition the row variable is often required to be both the input row and the output extended row. The unification engine treats rows structurally and applies the occurs check to prevent infinite types. That self-reference is blocked, producing the infinite type error.
Conditions that trigger the error
An infinite type error typically arises when a recursive type alias or data constructor refers to itself with a row that is extended by the same row variable, e.g., a definition where r appears in the result type and the result type is also the definition of r via row cons. Non-recursive row extension is allowed; self-referential extension is not.
Minimal verification steps for this case
- Create a minimal PureScript module with a recursive type that extends a row variable and compile with
purs compile to observe the reported error.
- Check compiler version with
purs --version. Behavior is version-sensitive and error wording can change across releases.
- Test a non-recursive row-polymorphic function for contrast to confirm row variables work outside recursion.
- If possible, try the same definition with the row variable made concrete to see if the error disappears.
One missing diagnostic detail that changes the recommendation is the exact PureScript compiler version and the minimal type definition producing the error. With those, the specific error wording and any version-dependent handling can be matched to the correct workaround.