Re: [sage-devel] Re: On scientific computing, Python and Julia
> In my code I actually have > > myfun{T <: Ring}(a::Poly{T}, b::Poly{T}) > > a lot. Is there a shorthand for this? I don't think so. According to https://github.com/JuliaLang/julia/issues/6984, it may be possible to have the following in the future: myfun{P<:Poly{<:Ring}}(a::P, b::P) -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: On scientific computing, Python and Julia
> or to constrain argument types, e.g. > myfun{T}(a::Poly{T}, b::Poly{T}) = a+b # a and b must be Polys of the same > type which is better expressed as : myfun{P<:Poly}(a::P, b::P) = a+b So a better example: myfun{T}(a::Poly{T}, b::Monomial{T}) = ... -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: On scientific computing, Python and Julia
> Sorry, I had some errors in this next bit. >> myfun(a :: Union(EuclideanPoly, Poly)) > It should have been > myfun{T <: Union(EuclideanPoly, Poly)}(a :: T) The first version is perfectly ok and more idiomatic in this case. You said earlier: > So typically function signatures will look like > fnname{T <: Z}(a :: T) > where we have: > a is a value > T is a type > Z is a typeclass Function signatures typically look like this only when T (a type variable) is used in the function definition, e.g. myfun{T}(::Poly{T}) = T or to constrain argument types, e.g. myfun{T}(a::Poly{T}, b::Poly{T}) = a+b # a and b must be Polys of the same type or to constrain the type variable, e.g. myfun{T<:Field}(a::Poly{T}) = 1/coeff(a)[1] # method of myfun working only with Polys over fields (and "myfun(a::Poly{<:Field})" is envisioned) Otherwise, "fname(a :: Z)" is the way, even if Z is abstract (typeclass). And even then, the concrete type of "a" can be referred to via "typeof(a)". And fname will be compiled separately for each concrete type it is called on. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.