You've defined a lot of methods here in shorthand notation: u(c::Float64, h::Float64, b, a) u(c::Float64, h::Float64, b) = u(c::Float64, h::Float64, b, a) u(c::Float64, h::Float64) = u(c::Float64, h::Float64, b) u(c::Float64, a) u(c::Float64) = u(c::Float64, a)
If you look at methods(u), you'll see all of these got defined when your method signature was expanded. To figure out which ones get called requires following the method chain. On Wed, Aug 26, 2015 at 12:22 PM Nils Gudat <[email protected]> wrote: > I'm defining a function with two methods as follows: > > a = 2. > b = 0.8 > > function u(c::Float64, h::Float64, b=b, a=a) > ((c/(h^b))^(1-a))/(1-a) > end > > function u(c::Float64, a=a) > c^(1-a)/(1-a) > end > > However, when calling u(2.), the result is -0.87..., which should be the > result of the function call u(2., 2.). > Clearly I misunderstand how multiple dispatch is working here - I thought > when defining a function f() with one method f(::Float64), and another > method f(::Float64, ::Float64), the two-argument version would only be > called if I'm actually supplying two arguments!? >
