(This was already asked in Julia Gitter, but I'm switching to the mailing 
list as this may better fit here than in a chat.)

"""
Is it possible to constraint the type of a bits type parameter? Something 
like f{N::Int}(x::SomeParamType{N}) where for N::Int I want to mean that N 
is an instance of Int, i.e., 1, 2, -10, 0, etc., and not that it is the 
DataType Int.
"""

Let me put it in another words:

To have parametric types to be restricted on the parameters they accept is 
just a matter of defining constructors in the right way. For example, 
although Array{Any, 1.5} is a valid type per se, one cannot create an 
instance of it.

Now imagine I have a type X{T} where it is possible that T is anything 
 (there are constructors), a DataType or as bits type instance.
I can create methods which dispatch when T is an Integer subtype:
f{T<:Integer}(x::X{T}) = "Integer subtype"
I can create methods which dispatch when T is a specific Integer subtype:
f(x::X{Int}) = "Int"
I can create methods which dispatch when T is a specific Int instance:
f(x::X{4}) = "4"

I wonder if it is possible to define a method which will dispatch on any 
Int instance (be it 1, 2, 0, -10), something like:
f{N::Int}(x::X{N}) = "N"
so that
f(X{Int8}()) returns "Integer subtype",
f(X{Int}()) returns "Int",
f(X{4}()) returns "4", and
f(X{3}()) returns "N" ...

This was probably asked and replied somewhere else, but I couldn't find it.

Thanks,
Cheers,
Cristóvão

Reply via email to