-
Notifications
You must be signed in to change notification settings - Fork 90
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
[generics-rep] Trivial genericShow blows up the call stack #245
Comments
I get the same error for the following code:
For some reason it's fixed by changing
to
It might have something to do with the type being recursive, since I'm not able to reproduce the callstack error for @karljs's VVis datatype, but I can if I make it recursive. For example,
|
I also got similar error
when used implemented show for this types using generic type Name = String
type Only = Boolean
data Group t
= Describe Only Name (Array (Group t))
| SetExecution Execution (Array (Group t))
| It Only Name t
| Pending Name
data Result = Success | Failure Error
data Execution = Parallel | Sequential |
here is travis error https://travis-ci.org/purescript-spec/purescript-spec/builds/466438964#L1159 and commit purescript-spec/purescript-spec@48bdf25 in case someone wants to look into it at some point |
That one isn't quite so trivial, since the first case is not recursive, but thanks for the example! |
travis (CI) not trivial :p |
I stumbled across this while trying to find a smaller datatype for which the stack overflow error happens. This code results in a compile error 🤔 module A where
import Data.Generic.Rep
import Data.Show.Generic
import Data.Show
data Nat = Z | S Nat
derive instance Generic Nat _
instance Show Nat where show = genericShow
Curiously, that also fixes the compile error. |
This is a very common thing that's needed when defining generic instances (or perhaps more accurately, when using default member implementations) for recursive types. I think unless the recursion in the type appears under a lambda, the instance will always require eta expansion - otherwise we'll get stack overflow/infinite loops, much like the original example in this issue. This is a consequence of PureScript being strictly evaluated. I've not looked at this for a long time, but possibly the "actual" issue for the initial example is that the compiler should be detecting the cycle and failing to do so, since the eta expansion did fix second example given. In the past I argued for automatic eta expansion of these cases when we can detect them, but there wasn't much enthusiasm for it since it would be a bit magical and ad-hoc, but maybe there's a principled scheme that could be concocted that would make it acceptable. I just eta expand and move on these days. 😄 |
I have the following code in my library:
If I now load my code in a REPL and create the following trivial value:
This is a very small value, so I don't understand why this is blowing up the call stack. Could somebody help me understand please?
The text was updated successfully, but these errors were encountered: