-
Notifications
You must be signed in to change notification settings - Fork 6
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
new type deriving broken #115
Comments
up |
@dtaskoff in meantime can you use one of the work-around mentioned above? |
Sure, it's just that I changed a type from data to a newtype, and spent some time wondering why it didn't work. It's even written in the documentation already (to use |
cool. There is another related but slightly different issue which is that elm-street likes to generate record aliases for new types on elm side. But semantically it would be better to better to generate regular |
I'm not sure that it's a good idea to translate Haskell's |
it should not be alias. elm equivalent of
so generating types elm can unbox would not be less type safe on elm side. It would be more type safe because it would generate distinct type rather than alias so |
My bad, I misread |
no worries. this terminology is super confusing between Elm and Haskell..
that's a recipe for misunderstanding. I will try to bring this issue up internally at Holmusk but expect this issue will take some time to resolve. There is a lot of code in the wild which need to keep supporting without introducing major breakages. |
Deriving instances for
newtype
is broken in cases like:Json instances expect the value to be wrapped in tagged object while elm decoders are generated for json string values. Decoding therefore fails (at runtime).
Two other ways to derive the value work
This generates instances where both expect wrapping object to be present.
Derives the instance where json values are not boxed in json representation.
I think the later option is better in most cases but there is a disadvantage for types which might start as a newtype and later be changed to full
data
record. This often happens as hlint complains aboutdata
with single field. With 2nd approach the JSON representation in not compatible betweennewtype
anddata
so changing types fromnewtype
todata
is breaking change for the api.Related Issues
The text was updated successfully, but these errors were encountered: