Writing a subtype function