If I understand correctly, you want to pass an instance of Foo into fun2, 
which would then effectively call "fun1(Foo, Foo())".  I don't quite 
understand the use case... can you give an example of when the second 
"fun1" definition would be called?

On Friday, May 1, 2015 at 9:24:59 AM UTC-4, Tamas Papp wrote:
>
> 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 <t...@breloff.com <javascript:>> 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 
> >> 
>

Reply via email to