Is it possible (even if hacky and not advisable) to do something like the following? Forewarning: this is a contrived example that just happens to work as an MWE exercise for my use case.
Let Foo be some type whose definition I can’t control and with a fundamentally-incompatible inner constructor.
struct Foo{T}
x::T
Foo(x) = error()
end
Is it possible to declare a shadow implementation a la
struct _ShadowFoo{T}
x::T
end
and then cast an instance of this type to the type being shadowed?
reinterpret(Foo{Float64}, _ShadowFoo(1.0))
This use of reinterpret doesn’t seem to work for me and I haven’t been able to find a different function that achieves this effect.
I think it mostly uses the procedure that mkitti suggests, but it’s builtin and maybe does it in a way that is slightly more sophisticated and possibly more performant. See @less Base._reinterpret(ComplexF32, 1.0) for the source.