title: When is Julia's convert() used?
body: <p>At <a href="http://julia.readthedocs.org/en/latest/manual/conversion-and-promotion/" rel="noreferrer">http://julia.readthedocs.org/en/latest/manual/conversion-and-promotion/</a>, there is a discussion about adding integers to floats and so on, and and at the end it says</p>
  
  <blockquote>
    <p>User-defined types can easily participate in this promotion system by defining methods for conversion to and from other types, and providing a handful of promotion rules defining what types they should promote to when mixed with other types.</p>
  </blockquote>
  
  <p>From this I inferred that when defining my own numeric type, I simply needed to define how to convert it to a known type for it to work with functions on it. But I tried this and it doesn't seem to work:</p>
  
  <pre><code>julia&gt; type MyType
             n::Int
         end
  
  julia&gt; convert(::Type{Int}, x::MyType) = x.n
  convert (generic function with 1 method)
  
  julia&gt; convert(Int, MyType(1))
  1
  
  julia&gt; MyType(1) + 1
  ERROR: `+` has no method matching +(::MyType, ::Int64)
  </code></pre>