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

Pattern matching on built-in strings #15

Open
kyouko-taiga opened this issue Oct 29, 2018 · 0 comments
Open

Pattern matching on built-in strings #15

kyouko-taiga opened this issue Oct 29, 2018 · 0 comments
Labels
discussion Further discussion is requested enhancement New feature or request

Comments

@kyouko-taiga
Copy link
Owner

There's currently no way to match built-in strings with anything but identify. In other words, one can write the following:

match s
  with "one" :: 1
  with "two" :: 2

But one can't check for any pattern that would match only parts of the string (e.g. the character at specific position). Although less impactful, note that built-in integers expose a similar problem.

One solution could be to map the built-in strings to an algebraic type such as #cons(_: Char, _: String) or #empty, which would make them naturally expressible in the language. Hence, the syntax with double quotes would be merely a syntactic sugar for #cons("a", cons("b", ....

Another direction would be to provide a built-in function to extract a specific character (e.g. char(in:at:)) and use identity matching, e.g.:

match char(in: s, at: 0)
  with "a" :: "the string starts with 'a'"
  // ...

Note that both solutions would require a built-in Char type.

@kyouko-taiga kyouko-taiga added enhancement New feature or request discussion Further discussion is requested labels Oct 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Further discussion is requested enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant