I’m trying to implement a new string type consisting only of the characters [A-Z] and [0-9]:
abstract type AbstractMyString <: AbstractString end struct MyString <: AbstractMyString str::String MyString(str) = begin ismatch(CSE, str) || error("string contains illegal characters") return new(str) end end const CSE = r"^.([A-Z]|[0-9])+$"
The problem I have is that I want
MyString to work in functions that expect
String. For example, I get the following error:
a = MyString("ASD1") "Error showing value of type MyString: ERROR: you must implement endof(MyString)
Which can be remedied by preventing the REPL from trying to print
a, using a semi colon.
I thought that I could declare everything to be a subtype of
AbstractString (as I cannot declare it to be subtype of
String) and expect that everything that works with
AbstractString to work with
MyString. Where did I go wrong? How can I inherit the things that work with