Not really --- I wanted to dispatch on something being an _instance_ of
a type that is a DataType. Having reread the manual, I don't think that
is possible directly, but works with one level of indirection:
fun1(T::DataType,x) = "do something with $x"
fun1(T, x) = "this is not a datatype"
fun2{T}(x::T) = fun1(T,x)
type Foo end
fun2(Foo())
That said, I realized that DataType is not what I need.
Best,
Tamas
On Thu, Apr 30 2015, Tom Breloff <[email protected]> wrote:
> Is this what you're looking for?
>
>
> julia> yyy(x::DataType) = true
> yyy (generic function with 1 method)
>
>
> julia> yyy(x) = false
> yyy (generic function with 2 methods)
>
>
> julia> yyy(Int)
> true
>
>
> julia> yyy(5)
> false
>
>
>
>
> On Thursday, April 30, 2015 at 11:04:02 AM UTC-4, Tamas Papp wrote:
>>
>> This is toy problem that came up in the context of something larger,
>> reduced to be simple so that I can ask about it more easily.
>>
>> Suppose I want to implement the function
>>
>> is_instanceof_datatype(x) = is(typeof(x),DataType)
>>
>> using dispatch: a default method that is
>>
>> is_instanceof_datatype(x) = false
>>
>> and some other method which only gets called when x is an instance of a
>> DataType:
>>
>> is_instanceof_datatype{ ... }(x::T) = true # how to dispatch
>>
>> but I don't know how to do the latter, hence the ....
>>
>> The context is that I want to write a method that, for instances of
>> DataTypes, returns the slots in a given order, but for other values it
>> does something else, and I don't know how to do this.
>>
>> Best,
>>
>> Tamas
>>