 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.types, constraint.types
+    if toMatchTypes (freshInstance ctx, type).type.types, constraint.types
       return validIdentifier name
   throw new Error "no instance for #{safePrintType constraint}"
 

constraintsFromInstance = (ctx, constraint) ->
  {className, type} = constraint
  for instance in (ctx.classNamed className).instances
    # log "trying to find the instance", (printType instance.type.type), (printType constraint)
    substitution = toMatchTypes instance.type.type.types, constraint.types
    if substitution
      ctx.extendSubstitution substitution
      return map ((c) -> substitute substitution, c), instance.type.constraints
  null

_names = (list) ->

      jsNoop()
    else
      freshConstraints = freshInstanceType.constraints
      instance = quantifyAll (new Constrained freshConstraints,
        (new ClassConstraint instanceType.className, freshInstanceType.type))
      ## if overlaps ctx, instance
      ##   malformed 'instance overlaps with another', instance
