Skip to content
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 ord/chr functions #16

Closed
neil-da opened this issue Feb 21, 2019 · 8 comments · Fixed by #1937
Closed

Add ord/chr functions #16

neil-da opened this issue Feb 21, 2019 · 8 comments · Fixed by #1937

Comments

@neil-da
Copy link
Contributor

neil-da commented Feb 21, 2019

Requested by @raphael-speyer-da and @andrae-da so they can pack/unpack strings. Concretely, something like Text -> [Int] and [Int] -> Text, or on single Int, or something around that area.

@ghost ghost transferred this issue from another repository Mar 31, 2019
@ghost ghost added the component/daml-lf DAML-LF label Mar 31, 2019
@ghost ghost added this to the Language milestone Mar 31, 2019
@neil-da neil-da added the discussion Things to be discussed and decided label May 21, 2019
@neil-da
Copy link
Contributor Author

neil-da commented May 21, 2019

@bitonic - what's your thoughts on this request?

@bitonic
Copy link
Contributor

bitonic commented May 22, 2019

@neil-da I'd be OK with it, I think Text -> [Int] makes the most sense.

@neil-da
Copy link
Contributor Author

neil-da commented May 23, 2019

As a roadmap for adding new primitives: https://github.com/digital-asset/daml/pull/1346/files

@remyhaemmerle-da
Copy link
Collaborator

remyhaemmerle-da commented May 29, 2019

1 - (naive question) Why explode and implode are not good enough ?

2 - Do we really want non type safe conversion ? I mean, wouldn't it better to introduce a proper Unicode Char type ?

3- In case we go for Int, what do we do when given invalid code points in input ?

Note we have to be sure no subrogate (codepoints ranging from 0xd800 to 0xdfff) ends up in our strings, otherwise we will have troubles with or java UTF16 encoding.

@ndmitchell
Copy link
Contributor

Working with characters as code points is soemtimes useful. Implode/explode don't let you do that, and Char is only useful if you can work on it as an Int too, so you might as well use Int and if people want some tiny extra type safety do it in DAML as a newtype.

I would suggest error on invalid input, since it's a pretty low level function anyway so people should pay attention.

@remyhaemmerle-da
Copy link
Collaborator

remyhaemmerle-da commented May 31, 2019

Therefore we will have to new builtins:

  • FROM_TEXT_CODEPOINTS: Text -> [Int64]
  • TO_TEXT_CODEPOINTS: [Int64] -> Text

The later will crash if it finds an Int64 which is not between 0x0000 and 0xd7ff or between 0xe000 and 0x10ffff (bounds included).

@remyhaemmerle-da remyhaemmerle-da self-assigned this Jun 3, 2019
@remyhaemmerle-da remyhaemmerle-da removed the discussion Things to be discussed and decided label Jun 3, 2019
@remyhaemmerle-da
Copy link
Collaborator

The two builtins are now available in DAML-LF dev version.
Language team can start to integrate to be accessible from the surface language.

This will be integrate in DAML-LF 1.6 together with enum type.

@remyhaemmerle-da remyhaemmerle-da removed their assignment Jun 4, 2019
@bitonic
Copy link
Contributor

bitonic commented Jun 6, 2019

I believe this is done now that #1536 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants