agrafix / elm-bridge

Haskell: Derive Elm types from Haskell types
BSD 3-Clause "New" or "Revised" License
100 stars 27 forks source link

Use EveryDict instead of List of Tuples #19

Closed fendor closed 3 years ago

fendor commented 7 years ago

Because of Elm's rather weird situation with comparable, the Dict in the core library can not take arbitrary types as a key.

This raises the inconvenience to substitute data structures with a non-comparable type, to be rewritten to the following form List ( k, v ) where k is the key and v the value. This can cause a performance issue on large data-sets and also inconvenient access-functions which have to be defined by the programmer.

For this reason, my fork solves this problem by declaring an additional dependency on the elm-all-dict-library and replacing all occurrences of the form List ( k, v ) and Dict comparable v to EveryDict k v.

The tests have been updated and run, and the fork is currently used in a project without a problem, but I think some use-cases have not been tested yet.

I also defined own function for decoding and encoding EveryDict which are based on the functions encodeMap and decodeMap from json-helpers.

bartavelle commented 7 years ago

I don't think it is acceptable to impose an additional constraint by default. However, I think it might be possible to design a custom alteration that would use that EveryDict module. That might make it really easy to support both plain Dict for those who don't care or don't have the performance problem, and those who need EveryDict.

fendor commented 7 years ago

You mean, an additional derive option? For example:

-- | Note that This default set of options is distinct from that in
-- the @aeson@ package.
defaultOptions :: A.Options
defaultOptions
  = A.defaultOptions
  { {- ommit other fields for clarity -}
  ...
  , A.useEveryDict            = False
  }

But I think this would require an additional argument to at least makeElmModuleWithVersion. Probably to a lot of others as well, since I use custom encoding and decoding functions.

bartavelle commented 7 years ago

No, I mean the first argument to makeModuleContentWithAlterations. What I linked to in the previous message is the default "alteration", that is used with makeModuleContent.

fendor commented 7 years ago

OK, I think I understand what you mean, I will look into it later and squash these comments, sorry, it was not possible to edit these from phone

fendor commented 3 years ago

I have currently no intention on working on this, thus I am closing the PR.