Thanks, creating an IntParam or IntVal type does seem like the best option 
if the type constraint is not available.

Another interesting workaround I came across is:

f{N}(::Type{Val{N}}, ::Type{Int}=typeof(N)) = N

which will throw a no-method error if you call it with non-Ints. Of course 
you can get around it easily by just passing Int as the second argument but 
at least there's some automated checking.

On Thursday, May 21, 2015 at 6:30:05 AM UTC-4, Simon Danisch wrote:
>
> So f will look like this now:
> *f{N}(x::IntParam{N}*) instead of *f{N}(x::Type{IntParam{N}}).*
>
> Am Mittwoch, 20. Mai 2015 23:28:26 UTC+2 schrieb Josh Langsfeld:
>>
>> I want to implement some functionality in multiple methods and have the 
>> dispatch controlled by an Int variable "N". The trick is I want one method 
>> to be called if N == 0 and another one to be called for all other values of 
>> N. Is there a way I can do this with "Val{N}" without making the method 
>> applicable to everything? That is, can I write a generic method 
>> "func(::Val{N}) and constrain N to be an Int only?
>>
>

Reply via email to