I tried this too, to override the method for Array{CIGAR, 1} but it still 
does not work:

function Base.show(io::IO, cigarstr::Array{CIGAR, 1})
    write(io, convert(String, cigarstr))
end


On Tuesday, August 11, 2015 at 9:22:09 AM UTC+1, Mauro wrote:
>
> I think you cannot create a show method for a typealias as it is 
> indistinguishable from the type it aliases. 
>
> On Mon, 2015-08-10 at 19:07, Ben Ward <axolotl...@gmail.com <javascript:>> 
> wrote: 
> > Hi, I have implemented a basic immutable type with a type alias for a 
> vector of 
> > said type: 
> > 
> > immutable CIGAR 
> >   OP::Operation 
> >   Size::Int 
> > end 
> > 
> > 
> > function CIGAR(op::Char, size::Int) 
> >   return CIGAR(Operation(op), size) 
> > end 
> > 
> > 
> > function convert(::Type{String}, cigar::CIGAR) 
> >   return "$(cigar.Size)$(Char(cigar.OP))" 
> > end 
> > 
> > 
> > function show(io::IO, cigar::CIGAR) 
> >   write(io, convert(String, cigar)) 
> > end 
> > 
> > 
> > typealias CIGARString Vector{CIGAR} 
> > 
> > 
> > function convert(::Type{CIGARString}, str::String) 
> >   matches = matchall(r"(\d+)(\w)", str) 
> >   cigarString = Vector{CIGAR}(length(matches)) 
> >   @inbounds for i in 1:length(matches) 
> >     m = matches[i] 
> >     cigarString[i] = CIGAR(m[end], parse(Int, m[1:end-1])) 
> >   end 
> >   return cigarString 
> > end 
> > 
> > 
> > macro cigar_str(str) 
> >   return CIGARString(str) 
> > end 
> > 
> > I also want to define a show method for the alias CIGARString, so as it 
> is 
> > converted to a string that can be used with a show method: 
> > 
> > function convert(::Type{String}, cigarString::CIGARString) 
> >   outString = "" 
> >   for cigar in cigarString 
> >     outString *= String(cigar) 
> >   end 
> >   return outString 
> > end 
> > 
> > 
> > function show(io::IO, cigarstr::CIGARString) 
> >   write(io, convert(String, cigarstr)) 
> > end 
> > 
> > However the output a see on the REPL is: 
> > 
> > 
> > 3-element Array{Bio.Align.CIGAR,1}: 
> > 
> > 
> > 5M 
> > 
> > 
> > 5N 
> > 
> > 
> > 5M 
> > 
> > 
> > So, rather than the show method for CIGARString being called, the show 
> method 
> > for CIGAR is being called repeatedly for every element in the 
> CIGARString 
> > vector. How do I get Julia to use the show method I want for 
> CIGARString? 
> > 
> > Thanks. 
>
>

Reply via email to