lpeterse/HiggsSet — comment on commit 6eed0c102acce4b1ee5a3316beec2ff2ddbb8795
File:  line 0
By lpeterse:

~~~ .haskell
share hs = shareThread . shareIP
where
shareThread x = case HS.lookup (CThread $ thread'4 x) hs of
Nothing -> x
Just y -> let k = thread'4 y
in x { thread'4 = k }
shareIP x = case HS.lookup (CIp $ userIp'2 $ user'4 x) hs of
Nothing -> x
Just y -> x { user'4 = (user'4 x) { userIp'2 = userIp'2 (user'4 y) } }
~~~

This is from one of my projects. Several set elements might have equal threads or IPs. Unfortunately, haskell does not unify them in terms of memory. Equal (in terms of `==`) values point to different objects in memory. By implementing the `share` method you can make all references of an equal value show to the same object. This doesn't change the behaviour of your program at all. It just saves you some memory.