<p dir="auto">The Go language has this cool feature for struct composition where if you put one struct after another's values, its values are inherited into the other.</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="type foo1 struct {
    bar   string
}
type foo2 struct {
    baz   string
    foo1  // foo2 now also has the field &quot;bar&quot; inherited from foo1
}"><pre class="notranslate"><span class="pl-k">type</span> <span class="pl-smi">foo1</span> <span class="pl-k">struct</span> {
    <span class="pl-c1">bar</span>   <span class="pl-smi">string</span>
}
<span class="pl-k">type</span> <span class="pl-smi">foo2</span> <span class="pl-k">struct</span> {
    <span class="pl-c1">baz</span>   <span class="pl-smi">string</span>
    <span class="pl-smi">foo1</span>  <span class="pl-c">// foo2 now also has the field "bar" inherited from foo1</span>
}</pre></div>
<p dir="auto">This seems like it would fit well into Julia.</p>
<p dir="auto">My suggested implementation would be:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="struct foo1
    bar::String
end

struct foo2
    baz::String
    foo1...
end"><pre class="notranslate"><span class="pl-k">struct</span> foo1
    bar<span class="pl-k">::</span><span class="pl-c1">String</span>
<span class="pl-k">end</span>

<span class="pl-k">struct</span> foo2
    baz<span class="pl-k">::</span><span class="pl-c1">String</span>
    foo1<span class="pl-k">...</span>
<span class="pl-k">end</span></pre></div>
<p dir="auto">Thanks for taking the time to read this! It would be yet another pretty nifty trick that Julia could use.</p>
<p dir="auto">Julia Version 0.3.0-prerelease+355 (2013-12-08 02:02 UTC)<br>
64-bit Linux (Kubuntu 13.10)</p>
<p dir="auto">A brief discussion about this is also at <a href="https://groups.google.com/forum/#!topic/julia-users/8tMwmFQZFrc" rel="nofollow">https://groups.google.com/forum/#!topic/julia-users/8tMwmFQZFrc</a></p>
<p dir="auto">There are a couple of situations where running methodswith function does not give the expected result. The returned report can either be missing expected methods, report the same method twice, or a combination of missing and duplicated methods.</p>
<h2 dir="auto">Scenario 1: Querying a local package.</h2>
<ul dir="auto">
<li>Create package, eg ExamplePkg via Pkg.generate("ExamplePkg","MIT")</li>
<li>Complete ExamplePkg.jl with attached</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="module ExamplePkg

# package code goes here
export TwoVals, addtwovals

type TwoVals
    val1
    val2
end

function addtwovals(v::TwoVals)
    v.val1 + v.val2
end

function addtwovals(v1::TwoVals, v2::TwoVals)
    v1.val1 + v1.val2 + v2.val1 + v2.val2
end

function addtwovals(v::TwoVals)
    v.val1 + v.val2
end

function addtwovals(v1::TwoVals, v2::TwoVals)
    v1.val1 + v1.val2 + v2.val1 + v2.val2
end

end # module"><pre class="notranslate"><code class="notranslate">module ExamplePkg

# package code goes here
export TwoVals, addtwovals

type TwoVals
    val1
    val2
end

function addtwovals(v::TwoVals)
    v.val1 + v.val2
end

function addtwovals(v1::TwoVals, v2::TwoVals)
    v1.val1 + v1.val2 + v2.val1 + v2.val2
end

function addtwovals(v::TwoVals)
    v.val1 + v.val2
end

function addtwovals(v1::TwoVals, v2::TwoVals)
    v1.val1 + v1.val2 + v2.val1 + v2.val2
end

end # module
</code></pre></div>
<ul dir="auto">
<li>In REPL the following can be seen</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; using ExamplePkg

julia&gt; t1 = TwoVals(1,2)
TwoVals(1,2)

julia&gt; t2 = TwoVals(100,200)
TwoVals(100,200)

julia&gt; addtwovals(t1)
3

julia&gt; addtwovals(t1, t2)
303

julia&gt; methods(addtwovals)
#2 methods for generic function &quot;addtwovals&quot;:
addtwovals(v::TwoVals) at /home/johng/.julia/ExamplePkg/src/ExamplePkg.jl:20
addtwovals(v1::TwoVals,v2::TwoVals) at /home/johng/.julia/ExamplePkg/src/ExamplePkg.jl:24

julia&gt; methodswith(TwoVals)

julia&gt; "><pre class="notranslate"><code class="notranslate">julia&gt; using ExamplePkg

julia&gt; t1 = TwoVals(1,2)
TwoVals(1,2)

julia&gt; t2 = TwoVals(100,200)
TwoVals(100,200)

julia&gt; addtwovals(t1)
3

julia&gt; addtwovals(t1, t2)
303

julia&gt; methods(addtwovals)
#2 methods for generic function "addtwovals":
addtwovals(v::TwoVals) at /home/johng/.julia/ExamplePkg/src/ExamplePkg.jl:20
addtwovals(v1::TwoVals,v2::TwoVals) at /home/johng/.julia/ExamplePkg/src/ExamplePkg.jl:24

julia&gt; methodswith(TwoVals)

julia&gt; 
</code></pre></div>
<p dir="auto">Problems with above :</p>
<ul dir="auto">
<li>Expected to see the two 'addtwovals' methods reported, however there is nothing reported at all.</li>
</ul>
<h2 dir="auto">Scenario 2: Querying an installed third-pary package.</h2>
<ul dir="auto">
<li>Install WebSockets package via adding to .julia/REQUIRE file and doing a Pkg.resolve()</li>
<li>IN REPL the following can be seen</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; using WebSockets                                                                                                                                                                                                                                                                                                                                                                                                  
julia&gt; methodswith(WebSocket)                                                                                                                                                                                     
isopen(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:126                                                                                                                                       
read(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:227                                                                                                                                         
write(ws::WebSocket,data) at /home/johng/.julia/WebSockets/src/WebSockets.jl:97                                                                                                                                    
close(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:115                                                                                                                                        
read(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:227                                                                                                                                         
write(ws::WebSocket,data) at /home/johng/.julia/WebSockets/src/WebSockets.jl:97                                                                                                                                    
close(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:115

julia&gt; methods(send_ping)
#2 methods for generic function &quot;send_ping&quot;:
send_ping(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:107
send_ping(ws::WebSocket,data) at /home/johng/.julia/WebSockets/src/WebSockets.jl:107

julia&gt; methods(send_pong)
#2 methods for generic function &quot;send_pong&quot;:
send_pong(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:111
send_pong(ws::WebSocket,data) at /home/johng/.julia/WebSockets/src/WebSockets.jl:111"><pre class="notranslate"><code class="notranslate">julia&gt; using WebSockets                                                                                                                                                                                                                                                                                                                                                                                                  
julia&gt; methodswith(WebSocket)                                                                                                                                                                                     
isopen(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:126                                                                                                                                       
read(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:227                                                                                                                                         
write(ws::WebSocket,data) at /home/johng/.julia/WebSockets/src/WebSockets.jl:97                                                                                                                                    
close(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:115                                                                                                                                        
read(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:227                                                                                                                                         
write(ws::WebSocket,data) at /home/johng/.julia/WebSockets/src/WebSockets.jl:97                                                                                                                                    
close(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:115

julia&gt; methods(send_ping)
#2 methods for generic function "send_ping":
send_ping(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:107
send_ping(ws::WebSocket,data) at /home/johng/.julia/WebSockets/src/WebSockets.jl:107

julia&gt; methods(send_pong)
#2 methods for generic function "send_pong":
send_pong(ws::WebSocket) at /home/johng/.julia/WebSockets/src/WebSockets.jl:111
send_pong(ws::WebSocket,data) at /home/johng/.julia/WebSockets/src/WebSockets.jl:111
</code></pre></div>
<p dir="auto">Problems with above:</p>
<ul dir="auto">
<li>read(), write(), close() methods are being listed twice for the same argument signature.</li>
<li>methodswith() return value is actually missing two functions send_ping() and send_pong() even though these are exported.</li>
</ul>