Re: [julia-users] Multiple dispatch and AbstractString

2016-02-10 Thread Ravi S
g(s::Union{Array{ASCIIString,1},Array{UTF8String,1}}) = println("here!")

Regards,
Ravi

On Wednesday, February 10, 2016 at 9:04:49 PM UTC+5:30, Mauro wrote:
>
> This is because Julia's types are invariant (it's easy to find in the 
> documentation once you know what to look for): 
>
> g{S<:AbstractString}(s::Vector{S}) = println("here!") 
>
> On Wed, 2016-02-10 at 16:23, Ján Dolinský  > wrote: 
> > Hi, 
> > 
> > I am facing the following dispatch problem: 
> > 
> > typealias MyString AbstractString 
> > 
> > g(s::Vector{MyString}) = println("here!") 
> > g(s::MyString) = println("there!") 
> > 
> > a = ["asd", "bvc", "qwerty"] 
> > b = ["asdť", "bvc", "qwerty"] 
> > 
> > 
> > println(typeof(a)) 
> > Array{ASCIIString,1} 
> > println(typeof(b)) 
> > Array{UTF8String,1} 
> > 
> > julia> g(a) 
> > ERROR: MethodError: `g` has no method matching g(::Array{ASCIIString,1}) 
> > 
> > julia> g(b) 
> > ERROR: MethodError: `g` has no method matching g(::Array{UTF8String,1}) 
> > 
> > julia> g(b[2]) 
> > there! 
> > 
> > julia> g(a[2]) 
> > there! 
> > 
> > How do I make the method g(s::Vector{MyString}) accept both vector of 
> > ASCIIString's or UTF8String's ? I expected the supertype AbstractString 
> to 
> > automatically match the both cases. 
> > 
> > Thanks, 
> > Jan 
> > 
> > p.s. I am designing some functions that consumes filesystem paths. I 
> assume, it 
> > is good idea to make those paths to be ::AbstractString ; I see many 
> functions 
> > related to filesystem in Julia manual to consume or return 
> ::AbstractString 
>


Re: [julia-users] Multiple dispatch and AbstractString

2016-02-10 Thread Mauro
This is because Julia's types are invariant (it's easy to find in the
documentation once you know what to look for):

g{S<:AbstractString}(s::Vector{S}) = println("here!")

On Wed, 2016-02-10 at 16:23, Ján Dolinský  wrote:
> Hi,
>
> I am facing the following dispatch problem:
>
> typealias MyString AbstractString
>
> g(s::Vector{MyString}) = println("here!")
> g(s::MyString) = println("there!")
>
> a = ["asd", "bvc", "qwerty"]
> b = ["asdť", "bvc", "qwerty"]
>
>
> println(typeof(a))
> Array{ASCIIString,1}
> println(typeof(b))
> Array{UTF8String,1}
>
> julia> g(a)
> ERROR: MethodError: `g` has no method matching g(::Array{ASCIIString,1})
>
> julia> g(b)
> ERROR: MethodError: `g` has no method matching g(::Array{UTF8String,1})
>
> julia> g(b[2])
> there!
>
> julia> g(a[2])
> there!
>
> How do I make the method g(s::Vector{MyString}) accept both vector of
> ASCIIString's or UTF8String's ? I expected the supertype AbstractString to
> automatically match the both cases.
>
> Thanks,
> Jan
>
> p.s. I am designing some functions that consumes filesystem paths. I assume, 
> it
> is good idea to make those paths to be ::AbstractString ; I see many functions
> related to filesystem in Julia manual to consume or return ::AbstractString


Re: [julia-users] Multiple dispatch and AbstractString

2016-02-10 Thread Mauro
On Wed, 2016-02-10 at 16:37, Ravi S  wrote:
> g(s::Union{Array{ASCIIString,1},Array{UTF8String,1}}) = println("here!")

Although, note that this only works for those two subtypes of AbstractString and
not any others.  Whereas

  g{S<:AbstractString}(s::Vector{S}) = println("here!")

works for all subtypes of AbstractString.

> Regards,
> Ravi
>
> On Wednesday, February 10, 2016 at 9:04:49 PM UTC+5:30, Mauro wrote:
>>
>> This is because Julia's types are invariant (it's easy to find in the
>> documentation once you know what to look for):
>>
>> g{S<:AbstractString}(s::Vector{S}) = println("here!")
>>
>> On Wed, 2016-02-10 at 16:23, Ján Dolinský > > wrote:
>> > Hi,
>> >
>> > I am facing the following dispatch problem:
>> >
>> > typealias MyString AbstractString
>> >
>> > g(s::Vector{MyString}) = println("here!")
>> > g(s::MyString) = println("there!")
>> >
>> > a = ["asd", "bvc", "qwerty"]
>> > b = ["asdť", "bvc", "qwerty"]
>> >
>> >
>> > println(typeof(a))
>> > Array{ASCIIString,1}
>> > println(typeof(b))
>> > Array{UTF8String,1}
>> >
>> > julia> g(a)
>> > ERROR: MethodError: `g` has no method matching g(::Array{ASCIIString,1})
>> >
>> > julia> g(b)
>> > ERROR: MethodError: `g` has no method matching g(::Array{UTF8String,1})
>> >
>> > julia> g(b[2])
>> > there!
>> >
>> > julia> g(a[2])
>> > there!
>> >
>> > How do I make the method g(s::Vector{MyString}) accept both vector of
>> > ASCIIString's or UTF8String's ? I expected the supertype AbstractString
>> to
>> > automatically match the both cases.
>> >
>> > Thanks,
>> > Jan
>> >
>> > p.s. I am designing some functions that consumes filesystem paths. I
>> assume, it
>> > is good idea to make those paths to be ::AbstractString ; I see many
>> functions
>> > related to filesystem in Julia manual to consume or return
>> ::AbstractString
>>


Re: [julia-users] Multiple dispatch and AbstractString

2016-02-10 Thread Ján Dolinský
Hi guys,

This indeed solves the problem. Thank you.

Jan

Dňa streda, 10. februára 2016 16:42:45 UTC+1 Mauro napísal(-a):
>
> On Wed, 2016-02-10 at 16:37, Ravi S  
> wrote: 
> > g(s::Union{Array{ASCIIString,1},Array{UTF8String,1}}) = println("here!") 
>
> Although, note that this only works for those two subtypes of 
> AbstractString and 
> not any others.  Whereas 
>
>   g{S<:AbstractString}(s::Vector{S}) = println("here!") 
>
> works for all subtypes of AbstractString. 
>
> > Regards, 
> > Ravi 
> > 
> > On Wednesday, February 10, 2016 at 9:04:49 PM UTC+5:30, Mauro wrote: 
> >> 
> >> This is because Julia's types are invariant (it's easy to find in the 
> >> documentation once you know what to look for): 
> >> 
> >> g{S<:AbstractString}(s::Vector{S}) = println("here!") 
> >> 
> >> On Wed, 2016-02-10 at 16:23, Ján Dolinský  >> > wrote: 
> >> > Hi, 
> >> > 
> >> > I am facing the following dispatch problem: 
> >> > 
> >> > typealias MyString AbstractString 
> >> > 
> >> > g(s::Vector{MyString}) = println("here!") 
> >> > g(s::MyString) = println("there!") 
> >> > 
> >> > a = ["asd", "bvc", "qwerty"] 
> >> > b = ["asdť", "bvc", "qwerty"] 
> >> > 
> >> > 
> >> > println(typeof(a)) 
> >> > Array{ASCIIString,1} 
> >> > println(typeof(b)) 
> >> > Array{UTF8String,1} 
> >> > 
> >> > julia> g(a) 
> >> > ERROR: MethodError: `g` has no method matching 
> g(::Array{ASCIIString,1}) 
> >> > 
> >> > julia> g(b) 
> >> > ERROR: MethodError: `g` has no method matching 
> g(::Array{UTF8String,1}) 
> >> > 
> >> > julia> g(b[2]) 
> >> > there! 
> >> > 
> >> > julia> g(a[2]) 
> >> > there! 
> >> > 
> >> > How do I make the method g(s::Vector{MyString}) accept both vector of 
> >> > ASCIIString's or UTF8String's ? I expected the supertype 
> AbstractString 
> >> to 
> >> > automatically match the both cases. 
> >> > 
> >> > Thanks, 
> >> > Jan 
> >> > 
> >> > p.s. I am designing some functions that consumes filesystem paths. I 
> >> assume, it 
> >> > is good idea to make those paths to be ::AbstractString ; I see many 
> >> functions 
> >> > related to filesystem in Julia manual to consume or return 
> >> ::AbstractString 
> >> 
>