ohnosequences / monochord

An exploration of string diagrams, monoidal categories and functional programming in the browser
GNU Affero General Public License v3.0
0 stars 1 forks source link

Rewriting the Dictionary structure in Elm #6

Closed mroman42 closed 9 years ago

mroman42 commented 9 years ago

As explained in #5, an Elm Dict needs the type of its keys to be comparable, and only a few primitive types are comparable. Because of that, it is not possible to use the core containers (Set, Dict) with user-defined data types.

It is more efficient to update a Dict a b than a -> b. That's why I find that a well-behaved dictionary structure could help us to define Graphs. It is easier to update with new edges and vertices.

An alternative approach is just to maintain the same a -> b and to do the updates as follows:

update : (a -> b) -> a -> b -> (a -> b)
update f x y z = if z == x then y else (f z)
mroman42 commented 9 years ago

I have completely rewrote the elm-core Dict structure to make it possible to use an arbitrary comparator. It can be seen in the newDict branch.

mroman42 commented 9 years ago

It is working as expected.