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

Behavior of toString relying on special constructor names #288

Closed
jvoigtlaender opened this Issue Jul 1, 2015 · 5 comments

Comments

Projects
None yet
2 participants
@jvoigtlaender
Contributor

jvoigtlaender commented Jul 1, 2015

For example, this currently leads to a runtime error:

import Graphics.Element

type V = RBNode

v = RBNode

main = Graphics.Element.show v

because the toString implementation in Native/Show.js sees the RBNode constructor name and "thinks" that type is a Dict (because the core implementation of Dict uses that constructor name as well).

Similarly, the Set type is not currently handled well in toString (after the #260/#263 change).

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Aug 2, 2015

Member

What do you propose to ameliorate this? I think we can make the risk of overlap small enough that this is not a concern in practice, and I'm not sure it'd be worth it to do anything fancier than that.

Member

evancz commented Aug 2, 2015

What do you propose to ameliorate this? I think we can make the risk of overlap small enough that this is not a concern in practice, and I'm not sure it'd be worth it to do anything fancier than that.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Aug 2, 2015

Contributor

I agree. Name the constructors something like XXX_Set or whatever. Actually I guess the RBNode etc. constructors are not much of an issue, but specifically the constructor Set on the right-hand side of type Set t = Set (Dict.Dict t ()) is too likely to be used by somebody else. So, I'm for renaming that constructor, plus changing the toString function in Native/Show.js by adding a separate case matching on that new constructor (and removing the Set-subcase of the case for Dicts there).

Contributor

jvoigtlaender commented Aug 2, 2015

I agree. Name the constructors something like XXX_Set or whatever. Actually I guess the RBNode etc. constructors are not much of an issue, but specifically the constructor Set on the right-hand side of type Set t = Set (Dict.Dict t ()) is too likely to be used by somebody else. So, I'm for renaming that constructor, plus changing the toString function in Native/Show.js by adding a separate case matching on that new constructor (and removing the Set-subcase of the case for Dicts there).

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Aug 2, 2015

Contributor

I addressed the Set-related part of this in https://github.com/elm-lang/core/pull/323.

The only other constructors that are treated somehow specially in the native toString function and that could potentially be occurring in a user's Elm code (and thus potentially lead to conflicts) are RBNode and RBEmpty. So, one might want to replace those by something more "exotic" throughout the whole repository. Like RBNode_Internal and RBEmpty_Internal or so.

Contributor

jvoigtlaender commented Aug 2, 2015

I addressed the Set-related part of this in https://github.com/elm-lang/core/pull/323.

The only other constructors that are treated somehow specially in the native toString function and that could potentially be occurring in a user's Elm code (and thus potentially lead to conflicts) are RBNode and RBEmpty. So, one might want to replace those by something more "exotic" throughout the whole repository. Like RBNode_Internal and RBEmpty_Internal or so.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Aug 3, 2015

Member

A convention like Node_elm_builtin might do the job better. Perhaps someone will think their thing really is internal in their context, but no one should think their node is an elm builtin. Seems like a fine change either way.

Member

evancz commented Aug 3, 2015

A convention like Node_elm_builtin might do the job better. Perhaps someone will think their thing really is internal in their context, but no one should think their node is an elm builtin. Seems like a fine change either way.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Aug 3, 2015

Contributor

Okay, same for Set_Internal then?

Contributor

jvoigtlaender commented Aug 3, 2015

Okay, same for Set_Internal then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment