How to dispatch this serializer function?

The error message says that it cannot decide which method to choose (it’s ambiguous). write(io, T::Tuple) matches the second argument, and write(io::IO, x) matches the first argument. So which method should it choose for write(io::IO, x::Tuple)?

So it suggests that you should define a method definition for write(io::IO, x::Tuple). So add ::IO to the method you defined.

But I suggest this definition instead of the loop:

Base.write(io::IO, x::Tuple) = write(io::IO, x...)
2 Likes