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

Built-in map type #634

Closed
raviqqe opened this issue Jan 15, 2022 · 1 comment · Fixed by #849
Closed

Built-in map type #634

raviqqe opened this issue Jan 15, 2022 · 1 comment · Fixed by #849
Labels
enhancement New feature or request

Comments

@raviqqe
Copy link
Contributor

raviqqe commented Jan 15, 2022

Problem

  • We do not have built-in map types.
  • Although there is a hash map type in a Core package, it lacks several features.
    • Type safety of keys and values
    • Intent communication

Solution

  • Add type and expression syntax for built-in map types.

Design

Type

  • Keys can be any comparable type.
  • Add hash and equal functions in type information.
    • Or compile them on demand?
  • Map types themselves may or may not be comparable depending on if they can include function types.
{string: string}
{number: Foo}
{[number]: none}
{[[number]]: none}
{{number: number}: none}

Expressions

Indexing

  • There is no whitespace between a map expression and the [ sign for syntax disambiguation.
    • Should we do the same for function calls too?
if x = xs[key] {
  ...
} else {
  ...
}
Alternative
if {key: v, ...xs} = xs {
  ...
} else {
  ...
}

Insertion

{string: number ...xs, "foo": 42}

Removal

{string: number ...xs, "foo"}

Merging

{string: number ...xs, ...ys}

Iteration

[string k for k, v in xs]

Size

Operator
#map
#list
Built-in function
  • Type: \(any) number
size(list)
size(map)
Generic function
  • Currently, the language doesn't have anything similar.
  • Potentially, other generic functions can be added.
    • @debug(xs ...[any])
    • @join(ss ...[string])
    • @delete(ss ...[string])
@size(map)
@raviqqe raviqqe added the enhancement New feature or request label Jan 15, 2022
@raviqqe raviqqe changed the title Map data structure Built-in map type Jan 21, 2022
@raviqqe
Copy link
Contributor Author

raviqqe commented Mar 5, 2022

Pen:

{string: number
  "foo": 1,
  "bar": 2,
}

Go:

map[string]int{
  "foo": 1,
  "bar": 2,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant