Your observation is correct. This remains the same with Julia 0.5.

`foo{T}` and `foo{T,N,P,S}` are different types. Due to invariance (see the
manual), the method will not match.

Whenever you define a type `foo{T,N,P,S}`, Julia automatically defines an
abstract type `foo{T}` as well, with `foo{T,N,P,S} <: foo{T}`.

-erik


On Mon, Aug 22, 2016 at 4:46 PM, Davide Lasagna <[email protected]>
wrote:

> Hi,
>
> Why do i need to specify all the parameters in the signature of methods
> that take `::Type` arguments?
>
> Demo:
> # define some parametric type
> julia> immutable foo{T, N, P, S}
>        end
>
> # this will not work, but it seems natural to omit trailing unused
> parameters
> julia> bar{T}(::Type{foo{T}}) = T
> bar (generic function with 1 method)
>
> # yes, it does not work
> julia> bar(foo{1, 2, 3, 4})
> ERROR: MethodError: `bar` has no method matching bar(::Type{foo{1,2,3,4}})
>
> # this will do the job,
> julia> bar2{T, N, P, S}(::Type{foo{T, N, P, S}}) = T
> bar2 (generic function with 1 method)
>
> # yep
> julia> bar2(foo{1, 2, 3, 4})
> 1
>
>
> In methods that take instances of a type it is usually not necessary to
> specify trailing unused parameter, meaning that, for instance
> baz{T}(f::foo{T}) = one(T)
> will work for any values of `N`, `P` and `S`.
>
> Thanks!
>
> P.S. This is on 0.4
>
>
>
>


-- 
Erik Schnetter <[email protected]>
http://www.perimeterinstitute.ca/personal/eschnetter/

Reply via email to