 instanceDictFor = (ctx, constraint) ->
   for {name, type} in (ctx.classNamed constraint.className).instances
     # TODO: support lookup of composite types, by traversing left depth-first
-    if toMatchTypes type.type.type, constraint.type
-    # if type.type.type.name is constraint.type.name
+    if toMatchTypes type.type.types, constraint.types
       return validIdentifier name
   throw new Error "no instance for #{safePrintType constraint}"
 

  else if type instanceof Constrained
    new Constrained (substituteList substitution, type.constraints),
      (substitute substitution, type.type)
  else if type instanceof ClassContraint
    new ClassContraint type.className, substitute substitution, type.type
  else
    type


  counter = {}
  classParams = newMap()
  for constraint in reducedConstraints when not isAlreadyParametrized ctx, constraint
    {className} = constraint
    names = typeNamesOfNormalized constraint
    typeMap = nestedLookupInMap classParams, names
    if not typeMap
      nestedAddToMap classParams, names, (typeMap = newMap())
    addToMap typeMap, className,
      "_#{className}_#{counter[className] ?= 0; ++counter[className]}"
  ctx.addClassParams classParams
