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

char.ToString() puts code into the string instead of char #736

Closed
Martin521 opened this Issue Aug 8, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@Martin521

Martin521 commented Aug 8, 2017

F#:
'1'.ToString() = "1"
Websharper:
'1'.ToString() = "49"

@Jand42

This comment has been minimized.

Show comment
Hide comment
@Jand42

Jand42 Aug 9, 2017

Member

Thanks for the report!

Way back it was decided that char is proxied by Numbers, so that arithmetics work on them without conversions in the generated code. F# string function and String module and type methods do the conversion back to string.

Possible fixes (alternatives):

  1. Use same logic as macro for string function for every ToString call. This would make '1'.ToString() to evaluate to "1" when used from both languages. (box '1').ToString() would still be "49".
  2. Switch proxy for char to be a 1-length String. For keeping all current features, this requires changing all proxies and RPC de/serializer logic related to char handling.
Member

Jand42 commented Aug 9, 2017

Thanks for the report!

Way back it was decided that char is proxied by Numbers, so that arithmetics work on them without conversions in the generated code. F# string function and String module and type methods do the conversion back to string.

Possible fixes (alternatives):

  1. Use same logic as macro for string function for every ToString call. This would make '1'.ToString() to evaluate to "1" when used from both languages. (box '1').ToString() would still be "49".
  2. Switch proxy for char to be a 1-length String. For keeping all current features, this requires changing all proxies and RPC de/serializer logic related to char handling.
@granicz

This comment has been minimized.

Show comment
Hide comment
@granicz

granicz Aug 21, 2017

Member

@Martin521 How about using string '1'?

Member

granicz commented Aug 21, 2017

@Martin521 How about using string '1'?

@granicz

This comment has been minimized.

Show comment
Hide comment
@granicz

granicz Aug 21, 2017

Member

@Jand42 Not sure if I like either options. BTW, (box '1').ToString() should also be "1".

Member

granicz commented Aug 21, 2017

@Jand42 Not sure if I like either options. BTW, (box '1').ToString() should also be "1".

@Martin521

This comment has been minimized.

Show comment
Hide comment
@Martin521

Martin521 Aug 21, 2017

@granicz Sure. Like with other some other incompatibilities, I have found workarounds, no problem. But having to find these issues in correct F# code makes Websharper less fun. And it makes porting, or maintaining "dual use" code, more difficult.
BTW Websharper / UI.Next is amazing, I really love it.

Martin521 commented Aug 21, 2017

@granicz Sure. Like with other some other incompatibilities, I have found workarounds, no problem. But having to find these issues in correct F# code makes Websharper less fun. And it makes porting, or maintaining "dual use" code, more difficult.
BTW Websharper / UI.Next is amazing, I really love it.

@Jand42

This comment has been minimized.

Show comment
Hide comment
@Jand42

Jand42 Aug 25, 2017

Member

Option 2 was implemented. System.Char is now translates to a 1-length string. A lot of string operations become a bit faster because of removing unneeded to/from conversions of char codes. Char arithmetic and range is still supported correctly with special handling.

Member

Jand42 commented Aug 25, 2017

Option 2 was implemented. System.Char is now translates to a 1-length string. A lot of string operations become a bit faster because of removing unneeded to/from conversions of char codes. Char arithmetic and range is still supported correctly with special handling.

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