Fix a unique id bug

Under rare circumstances, more than one constant could end up with the
same unique identifier.  This was a problem with using get/put in the
State monad and overwriting state updates in between the get and put.