Julia Yes, that's what I suggested.
You could instead look at type promotion <http://docs.julialang.org/en/release-0.4/manual/conversion-and-promotion/#defining-promotion-rules>. Defining a rule that converts `(C, C)` to `(A, A)` might work, if you declare the `implicit_match` function as type conversion. -erik On Sat, Feb 27, 2016 at 3:49 PM, Julia Tylors <[email protected]> wrote: > abstract CC; > type C <: CC > #some stuff > end > > +{T<:CC}(x::T, y::T) = convert(A,x) + convert(A,y) > > > This is what you are saying right? > If it is, I don't want to define any more + function, i want it to be > handled by some sort of a dispatch trick, if it exists... > > On Saturday, February 27, 2016 at 12:29:57 PM UTC-8, Erik Schnetter wrote: >> >> You can define an abstract type CC that is a super type of C, and define a >> fallback + operator for it that converts C to A. If an operator + for C is >> defined, it will be used instead of the CC operator +. >> >> -erik >> >> On Saturday, February 27, 2016, Julia Tylors <[email protected]> wrote: >> > Hi, I have a problem i need an implicit call, I wonder whether there is >> > a way to do what i have in mind. >> > >> > +(x::A,y::A) = C(x,y) >> > implicit_match(c::C) = #returns type A, >> > function foo(x::A,Y::A) >> > (x+y) + (x+y) >> > end >> > >> > >> > As you may see in the function foo, once (x+y) is executed, it returns >> > an instance of type C. >> > now second operation becomes in type C+C , but there is no function like >> > +(c1::C, c2::C), but i have a match function (implicit_match) which can >> > return an instance of A by looking at the input instance of type C >> > I want this implicit function to be executed once +(::C,::C) is not >> > found. >> > Can we do something like this? >> > I don't like to define +(::C,::C) or generate +(::C,::C) using a macro. >> > Thanks >> >> -- >> Erik Schnetter <[email protected]> >> http://www.perimeterinstitute.ca/personal/eschnetter/ >> > -- Erik Schnetter <[email protected]> http://www.perimeterinstitute.ca/personal/eschnetter/
