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

Consider adding char as a primitive type #2937

Open
mohammadfawaz opened this issue Oct 4, 2022 · 3 comments
Open

Consider adding char as a primitive type #2937

mohammadfawaz opened this issue Oct 4, 2022 · 3 comments
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: parser Everything to do with the parser language feature Core language features visible to end users P: high Should be looked at if there are no critical issues left

Comments

@mohammadfawaz
Copy link
Contributor

mohammadfawaz commented Oct 4, 2022

Similar to https://doc.rust-lang.org/book/ch03-02-data-types.html#the-character-type

This would be useful for the String library that is being developed. For example, the push function would look like:

fn push(mut self, value: char)
@mohammadfawaz mohammadfawaz added compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: parser Everything to do with the parser language feature Core language features visible to end users labels Oct 4, 2022
@adlerjohn
Copy link
Contributor

Shower thought: chars are just one-element strings, so anywhere a char is used, a string can be used.

@otrho
Copy link
Contributor

otrho commented Oct 6, 2022

char would be a copy type and str is a ref type so internally they'd be treated quite differently. Might make substituting chars for strings non-trivial.

@Centril
Copy link
Contributor

Centril commented Oct 6, 2022

If we wish to have unicode support for our strings, I think this is a great idea / must-have.

Shower thought: chars are just one-element strings, so anywhere a char is used, a string can be used.

For unicode purposes, this doesn't work. str[N] is based on the number of bytes, but chars would be treated in memory as u32 (+ special rules) to back the possibility of emojis and such.

@mohammadfawaz mohammadfawaz added the P: high Should be looked at if there are no critical issues left label Oct 15, 2022
@bitzoic bitzoic mentioned this issue Jun 28, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: parser Everything to do with the parser language feature Core language features visible to end users P: high Should be looked at if there are no critical issues left
Projects
None yet
Development

No branches or pull requests

4 participants