Typealias with a custom constructor

Is there a way to create a type alias with a custom constructor?

FloatyMcFloatFace = Float64
FloatyMcFloatFace(x) = new(x+1)

No. Aliases are just another name for exactly the same type, so they can’t have separate methods.

1 Like

Is there a good way to have a custom type that automatically inherits all the methods of the “aliased” type? I would like to have a custom type that has all the properties and functions of a Matrix but has custom show and constructors.

You have to implement some methods and make your type a subtype of AbstractMatrix: Interfaces · The Julia Language

I was trying to avoid that. Matrix type is fairly well documented but for a lot of types that would mean run the code and implement the method from the error stack trace. I need a catch all :slight_smile:


could help but you can’t avoid doing:

Lazy.@forward looks great. Thanks!