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 Dict and Set primitive for Map, HashMap, IntMan, Set, HashSet and IntSet #26

Open
chshersh opened this issue Feb 15, 2019 · 5 comments
Labels
ast Elm definition AST (and other) enhancement New feature or request

Comments

@chshersh
Copy link
Contributor

Elm has standard data types called Dict and Set for container packages:

It's probably a good idea to support them too for common Haskell containers.

@chshersh chshersh added enhancement New feature or request ast Elm definition AST (and other) labels Feb 15, 2019
@arbus
Copy link
Member

arbus commented Oct 8, 2019

Some updates on this issue:

I have taken a stab at implementing this and my wip can be found in the branch arbus/26-Add-Dict-and-Set-primitive

This is straightforward for types of (Elm a) => Map Text a but a serious pain for anything else. Even for straightforward enum types that would normally serialize to just plain text, it can't be decoded on the elm side because elm requires its Dict types' keys to be of type comparable which is a special Ord,Eq constraint which only built-in types adhere to and we cannot extend it to support our custom types as well.

I'm not sure how useful the idea of implementing this only in the scenerio where the map key is a Text is useful.

@chshersh
Copy link
Contributor Author

chshersh commented Oct 8, 2019

@arbus Am I understanding correctly that the main problem here is that you can't have data types like Map MyEnum a or Set MyEnum in Elm because enums in Elm doesn't have required built-in interfaces implemented? So even if you can write decoder and encoder for such Map, you can't use it in Elm code, it will be a compile-time error, right?

@arbus
Copy link
Member

arbus commented Oct 8, 2019

Yes that is correct, only things that are comparable can be the key of a dict or be put in a set.

From the documentation:

A dictionary mapping unique keys to values. The keys can be any comparable type. This includes Int, Float, Time, Char, String, and tuples or lists of comparable types.

-- 

A set of unique values. The values can be any comparable type. This includes Int, Float, Time, Char, String, and tuples or lists of comparable types.

@chshersh
Copy link
Contributor Author

chshersh commented Oct 8, 2019

@arbus Okay, in that case I propose to put this issue on hold and keep your branch. It contains useful code for this feature. I also think that using Map Text a on frontend is awkward and will complicate our code. Maybe somebody will implement enum-map package with JSON encoders and decoders. Or maybe elm-0.20 will provide these builtin instances for enums. Who know in what ways our lives will be improved...

@turboMaCk
Copy link
Member

turboMaCk commented Apr 11, 2020

For the record these 2 packages (of mine, sorry for shameless promotion) are solving problem with comparable

Anyway, generating code for this would be still challenging become it would require generating key -> comparable functions.

My suggestion would be to:

  • Generate Set for IntSet
  • Generate Dict for IntMap
  • Generate List for Set
  • Generate List (key, value) for Map, Hashmap and AssocList.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ast Elm definition AST (and other) enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants