If I echo my story type in main, the tostring used is the default one for a type, and not the one I defined.
If I import story in main, then my tostring is used.
main.nim
import utils
let story = parseStory(...)
echo(story) # this prints the default object string. if I import story in this file, then the custom tostring is used.
utils.nim
import story
proc parseStory*(filename: string): Story =
...
story.nim
type
Story* = object
...
proc `$`*(s: Story): string =
....
Is there a way to print story with the custom representation I defined without importing it in main, by binding it with the type somehow?
I think "tying procedures to objects" is a planned compiler behaviour for the future, but I think the accepted behaviour currently is doing import story in this case. If you come across this situation where you specifically need utils but not story more than once, you can do this:
# utils.nim
import story
export story.`$`
proc parseStory*(filename: string): Story =
...