But do you agree that the usage of x::T as a formal parameter is quite
different when T is a type parameter compared to when it is a plain type?
I'm not 100% sure I grok what you're getting at, but *if *what you're
asking is whether I see a difference between foo(x::Real) and
Here is an example of the difference Toivo refers to (I think):
julia foo{T:Real}(a::Array{T},b::T) = T
foo (generic function with 1 method)
julia bar(a::Array{Real},b::Real) = Real
Correct me if I am wrong, but IMHO the comparison of the two functions in
Mauro's last post is not entirely fair for :: because the parametrized version
imposed an additional constraint which has nothing to do with ::
Essentially in the two cases the following types are required:
foo: T :
Yes, that is exactly the kind of example that I'm referring to. (As is the
example that started this thread as well.)
In all other cases, x::T is covariant in the sense that it allows typeof(x)
: T. But in an argument list when T is a type parameter to the same
method, x::T is instead invariant
On Fri, 2014-05-16 at 17:18, Toivo wrote:
Yes, that is exactly the kind of example that I'm referring to. (As is the
example that started this thread as well.)
Haha, well sometimes I just take a bit longer to figure things
out... ;-)
I suspect that the pragmatic rule that Julia follows is
it silently uses :: in a different sense than anywhere else in the language
I started writing a reply here, but realized it would be more instructive
to have it as an IJulia notebook, where we can actually inspect the values
of various statements along the way - take a look here
instead:
This is a good summary, cheers.
Maybe you include an example of a parametric function as well as was
discussed in this tread earlier? For instance:
julia foofoo{T:Real}(x::T,y::T) = x
foofoo (generic function with 1 method)
julia barbar(x::Real,y::Real) = x
barbar (generic function with 1
Although instructive, that example is almost identical to the corresponding
doc section
(http://julia.readthedocs.org/en/latest/manual/methods/#parametric-methods)
so I doubt I could add much value other than a link to the docs ;)
// T
On Thursday, May 15, 2014 11:39:53 AM UTC+2, Mauro wrote:
Although instructive, that example is almost identical to the corresponding
doc section
(http://julia.readthedocs.org/en/latest/manual/methods/#parametric-methods)
so I doubt I could add much value other than a link to the docs ;)
But isn't, for instance, your first examples also in the
On Thursday, 15 May 2014 10:59:07 UTC+2, Tomas Lycken wrote:
it silently uses :: in a different sense than anywhere else in the language
I started writing a reply here, but realized it would be more instructive
to have it as an IJulia notebook, where we can actually inspect the values
Yes, I think that you are right. What bothers me is that it silently uses :: in
a different sense than anywhere else in the language, and that I didn't realize
this after reading through the manual.
I might be wrong, but isn't that requirement (T===typeof(x)) strictly
mandatory to make diagonal dispatch work? If I define
issametype{T}(x::T, y::T) = true
issametype(x,y) = false
in a world where isa(x,T) is enough, and then call
issametype(1, 1.0)
I would get true because Julia can compile
I'm playing with defining Linked Lists in Julia. The version I'm struggling
with involves having a type parameter on the node and list, that indicates
the type of the data in the list.
These are the types:
~~~
type List{T}
head::Union(Node{T},Nothing)
end
type Node{T}
data::T
I noticed a similar issue recently, (but didn't report it directly:
https://github.com/JuliaLang/julia/issues/6717)
a{T}(::Array{T,1}, ::T) = T
does cannot match a function for T=Any
julia a({}, 1)
ERROR: no method a(Array{Any,1},Int64)
I see the same behavior in 0.2.1, so it isn't a recent
I've only come to suspect this recently, but I believe that type parameters
have always been a special case such that if T is a type parameter of a method,
then x::T in the argument list requires that T===typeof(x), not just isa(x, T)
as otherwise. I guess that this is deliberate, though I find
15 matches
Mail list logo