On Thursday, 28 August 2014 16:48:31 UTC+2, R. Fourquet wrote:
>
> > 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. 
>

Thanks very much for pointing that out. I was not aware of this trick! 

-- 
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.

Reply via email to