-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more CycleInDeclaration examples #333
base: master
Are you sure you want to change the base?
Conversation
Type class instance for recursive data type: | ||
```purs | ||
data Chain a | ||
= End a | ||
| Link a (Chain a) | ||
|
||
derive instance genericChain :: Generic (Chain a) _ | ||
|
||
-- This builds, but blows-up call stack and triggers a | ||
-- "too much recursion error". | ||
instance showChain :: Show a => Show (Chain a) where | ||
show = genericShow | ||
{- | ||
Fix the issue by replacing the above line with: | ||
show c = genericShow c | ||
-} | ||
``` | ||
https://try.purescript.org/?gist=32b78ce065d60427620cdd8d40777a1f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this could just be a link to the contents being added in #338?
### Additional Examples | ||
|
||
Mutually recursive functions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move the generic deriving example to be a link then we can change this header to be ### Mutual recursion
and just focus on this mutual recursion example. I think that fits better with how other errors use the Notes section.
Also, what do you think of trimming the example a little bit to something like this?
isEven :: Int -> Boolean
isEven n
| n == 0 = true
| otherwise = again (n - 1)
again :: Int -> Boolean
again = isEven
which also fails, producing this error:
The value of isEven is undefined here, so this reference is not allowed.
while checking that expression isEven
has type Int -> Boolean
in binding group isEven, again
This PR hasn't been merged because while this is about the CycleInDeclaration, it's really explaining places where eta-expansion is needed. However, it doesn't clarify why. So, I feel like it's incomplete. |
I found the
x = x
example a bit too minimal to figure out what's required to fix these errors.