 isMapEmpty = (set) ->
   set.size is 0
 
-mapSet =
 mapMap = (fn, set) ->
   initialized = newMap()
   for key, val of set.values
     addToMap initialized, key, fn val
+  initialized
+
+mapSet =
+rehashMap = (fn, set) ->
+  initialized = newMap()
+  for key, val of set.values
+    addToMap initialized, (fn key), val
   initialized
 
 filterSet =

  vars = subtractSets (findFree type), ctx.allBoundTypeVariables()
  quantify vars, type

# Takes a set of fixed type variables, a set of type variables which
# should be quantified and a list of constraints
# returns deferred and retained constraints
deferConstraints = (ctx, fixedVars, quantifiedVars, constraints) ->
  reducedConstraints = reduceConstraints ctx, constraints
  throw new Error "could not reduce constraints in deferConstraints" unless reducedConstraints
  isFixed = (constraint) ->
    # log fixedVars, constraint, (findFree constraint)
    isSubset fixedVars, (findFree constraint)
  [deferred, retained] = partition isFixed, reducedConstraints
  # TODO: handle ambiguity when reducedConstraints include variables not in
  # fixedVars or quantifiedVars

irDefinitionTranslate = (ctx, {type, expression}) ->
  finalType = substitute ctx.substitution, type
  reducedConstraints = reduceConstraints ctx, finalType.constraints
  ctx.updateClassParams()
  # TODO: what about the class dictionaries order?
  counter = {}
  classParams = newMap()
