       walked.js = ast.js
       walked
 
-irDefinition = (type, expression, id, bare) ->
-  {ir: irDefinitionTranslate, type, expression, id, bare}
+irDefinition = (type, expression, reference, bare) ->
+  {ir: irDefinitionTranslate, type, expression, reference, bare}
 
 # TODO: This must always wrap a function, because if the expression
 #       is not a function then it can't need type class dictionaries
 #       ^.___ not necessarily, we could have a tuple of functions or similar
-irDefinitionTranslate = (ctx, {type, expression, id, bare}) ->
+irDefinitionTranslate = (ctx, {type, expression, reference, bare}) ->
   finalType = substitute ctx.substitution, type
-  allConstraints = (addConstraintsFrom ctx, {id, type}, finalType).constraints
+  allConstraints = (addConstraintsFrom ctx,
+    {type, name: reference?.name, scopeIndex: reference?.scopeIndex}, finalType).constraints
   reducedConstraints =
     # if declaredType = ctx.typeForId id
     #   constraintsFromCanonicalType ctx, declaredType, finalType

  sub = matchType inferredType.type, (substitute ctx.substitution, type).type
  (substitute sub, inferredType).constraints

irReference = (name, id, type, arity) ->
  {ir: irReferenceTranslate, name, id, type, arity}

irReferenceTranslate = (ctx, {name, id, type, arity}) ->
  if ctx.isMethod name, type
    translateIr ctx, (irMethod type, name)
  else
    finalType = addConstraintsFrom ctx, {id, type}, substitute ctx.substitution, type
    classParams = dictsForConstraint ctx, finalType.constraints
    if classParams.length > 0
      params = map validIdentifier, arity
      (irFunctionTranslate ctx,
        params: params


nameTranslate = (ctx, atom, symbol, type) ->
  id = ctx.declarationId symbol
  ctx.addToUsedNames symbol
  translation =
    if atom.label is 'const'
