Hello, I just learned a couple of days ago that IO lists are a thing, and while playing around with them I ran into something that didn’t work when I expected that it would, and I’m curious if it’s something that just isn’t supported at the moment, or if there is some reason it shouldn’t work.
What I expected to work: a struct that implements String.Chars can be used in an IO list directly
Example:
defmodule Test do
defstruct []
end
defimpl String.Chars, for: Test do
def to_string(_v), do: "it worked!"
end
Using the contrived example above I expected the following lines would have the same result:
IO.puts "Aaaand...#{%Test{}}"
IO.puts ["Aaaand...", %Test{}]
…but the second line results in an argument error.
I can however make it work if I call to_string explicitly:
IO.puts ["Aaaand...", to_string(%Test{})]
Aaaand...it worked!
I’d love to know why this is the case (as well as if what I tried to do is silly and ruins the performance benefit somehow).