I'm not a Julia specialist but I think that for the last case one must do:

julia> g{T<:Integer}(v::Point{T}) = "Point... parametric type is Integer 
abstract class"
g (generic function with 1 method)

julia> g(p)
"Point... parametric type is Integer abstract class"

Anyway, I think that there must be a reason to allow the function 
definition the way you have put, or else it should not be allowed in the 
first place.
We may ask that on Julia users group...

On Tuesday, November 12, 2013 10:55:09 PM UTC, F. B. wrote:
>
> I had a try at this with Julia... unfortunately there is a problem there 
> because parametric type constructors are invariant, while they should be 
> covariant for this particular case:
>
> julia> immutable Point{T}
>           x::T
>           y::T
>        end
>
> julia> p = Point{Int64}(3, 5)
> Point{Int64}(3,5)
>
> julia> p2 = Point{Float64}(3.0, 5.0)
> Point{Float64}(3.0,5.0)
>
> julia> p.x
> 3
>
> julia> p.y
> 5
>
> julia> f(v::Point{Float64}) = "Point... parametric type Float64"
> f (generic function with 3 methods)
>
> julia> f(v::Point) = "Point... no parametric type"
> f (generic function with 1 method)
>
> julia> f(p2)
> "Point... parametric type Float64"
>
> julia> f(p)
> "Point... no parametric type"
>
> julia> f(v::Point{Int64}) = "Point... parametric type Int64"
> f (generic function with 2 methods)
>
> julia> f(p)
> "Point... parametric type Int64"
>
> If methods with detail are not matched, the more generic one is matched:
>
> julia> p3 = Point{String}("hello", "world")
> Point{String}("hello","world")
>
> julia> f(p3)
> "Point... no parametric type"
>
>
> The problem is here, parametric types break all inheritance relations:
>
> julia> g(v::Point{Integer}) = "Point... parametric type is Integer 
> abstract class"
> g (generic function with 1 method)
>
> julia> g(p)
> ERROR: no method g(Point{Int64})
>
> In Julia may approach is not possible, or at least it has to be handled in 
> another way.
>
> Another language, Scala, has a similar behavior as Julia, but allows to 
> put markers on parametric type to keep inheritance relations for derived 
> types, + for covariant, - for invariant.
>
> In my suggestion, this problem should be considered.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to