Promotion for arithmetic operations on @enum types

You can constrain the input by defining the inner constructor method as discussed in the Inner Constructor section of the Julia Docs. This could be achieved like this

struct CircPol <: Polarization
	type::Int
	CircPol(x::Int) = x == 1 || x == -1 ? new(x) : error("not valid polarization")
end

Alternatively however, if CircPol is a type that just stores another type why not make CircPol an abstract type that RightPol and LeftPol are subtypes of? They can both be a concrete type of their own with no fields and functions that need either one can accept the parent CircPol. Should then be possible to design functions and promotions as needed. (But I don’t know what I’m talking about usually so someone else should comment on if this is a good idea).

1 Like