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

Dictionaries #2159

Open
byorgey opened this issue Sep 29, 2024 · 1 comment · May be fixed by #2191
Open

Dictionaries #2159

byorgey opened this issue Sep 29, 2024 · 1 comment · May be fixed by #2191
Labels
Z-Feature A new feature to be added to the game.

Comments

@byorgey
Copy link
Member

byorgey commented Sep 29, 2024

It should be possible to program with dictionaries/maps in Swarm. Some options include:

  1. Now that we have recursive types, it's totally possible to just program dictionaries as a library, as is done in e.g. Haskell. For example we could define a recursive type of binary trees and implement maps as balanced binary trees storing key/value pairs allowing for $O(\log n)$-time operations. See Dictionary example #2161 .
  2. That works well in Haskell since GHC is an amazingly good optimizing compiler; in Swarm-lang it would result in a rather slow dictionary library. Taking a cue from e.g. Python, we could also have dictionaries built in as a language primitive, so under the hood they could use actual Haskell Maps.
  3. One could also imagine trying to co-opt the record system to build dictionaries, but (1) records can't be polymorphic in the key type, (2) the type of a record must strictly list all its fields, and (3) records have heterogeneous value types, whereas dictionaries are homogeneous in the value type.
@byorgey byorgey added the Z-Feature A new feature to be added to the game. label Sep 29, 2024
@xsebek
Copy link
Member

xsebek commented Sep 30, 2024

I started working on 1. in #2161. Records + Recursive types look promising, I wonder how performant they will be.

@xsebek xsebek linked a pull request Oct 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-Feature A new feature to be added to the game.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants