title: How to infer coercions?
body: <p>I would like to know how to infer coercions (a.k.a. implicit conversions) during type inference. I am using the type inference scheme described in <a href="http://people.cs.uu.nl/bastiaan/phdthesis/index.html" rel="noreferrer">Top Quality Type Error Messages</a> by Bastiaan Heeren, but I'd assume that the general idea is probably the same in all Hindley-Milner-esque approaches.</p>
  
  <p>It seems like coercion could be treated as a form of overloading, but the overloading approach described in this paper doesn't consider (at least not in a way I could follow) overloading based on requirements that the context places on return type, which is a must for coercions. I'm also concerned that such an approach might make it difficult to give priority to the identity coercion, and also to respect the transitive closure of coercibility. I can see sugaring each coercible expression, say <em>e</em>, to coerce(<em>e</em>), but sugaring it to coerce(coerce(coerce(... coerce(<em>e</em>) ...))) for some depth equal to the maximum nesting of coercions seems silly, and also limits the coercibility relation to something with a finite transitive closure whose depth is independent of the context, which seems (needlessly?) restrictive.</p>