Creating AbstractStrings




I face a problem when creating an AbstractString type. Maybe is not the best implementation. Nevertheless, I want to give it a try. Here is my toy-model which fails of course, because, it is not finished. I don’t know how to continue with it.

bitstype 32 MyChar

type MyString <: AbstractString
  MyString(arr::Array{MyChar,1}) = begin
    # What should be go here?
    x = new(length(arr))

# I'm only guessing
Base.endof(mystr::MyString) = mystr.len, i::Int) = unsafe_load(pointer_from_objref(mystr), i+1)

x = reinterpret(MyChar, 0x00000000)
y = reinterpret(MyChar, 0x00000001)

mystr = MyString([x,y])



You need a field to actually store the array in the type. And you don’t need a length field if you have an array field, since the length is stored in the array. And then you don’t need to declare a constructor, since the default will work.

type MyString <: AbstractString
Base.endof(mystr::MyString) = length(, i) = ([i], i+1)
Base.start(mystr::MyString) = 1
Base.done(mystr::MyString, i) = i > length(

If you want a string type with 32-bit code units, then maybe you should just use the UTF32String type from


Thanks @stevengj!!