Le mardi 19 avril 2016 à 11:58 +0200, Didier Verna a écrit :
> There's something I don't understand about them:
> 
> type Foo
>  val
>  double
>  function call(::Type{Foo}, val)
>    new(val, 2*val)
>  end
> end
This is an inner constructor, not an outer one. But you would usually
write it in a very different way. What you did is equivalent to the
much simpler:

type Foo
    val
    double
    function Foo(val)
        new(val, 2*val)
    end
end

Where did you get this convoluted idea?

> I understand here that the programmer explicitly provides a way to call
> Foo(3), but how does this prevent calls to Foo(3, 4) from being
> automatically defined as usual?
> 
> Does the language detect, in some way, the explicit specialization and
> stops doing it altogether?
AFAIK, yes. This doesn't prevent you from adding more inner
constructors manually. It's just that Julia doesn't create the default
inner constructor automatically if you add one manually, to leave you
full control.

This is all documented in the manual:
http://docs.julialang.org/en/stable/manual/constructors/


Regards

Reply via email to