I have a program with the following components:

  * a main.nim file, a utils.nim file and story.nim
  * story.nim defines a type Story and also its tostring procedure. A proc in 
utils returns the story object. main calls the proc to get the story and prints 
it.
  * I need to import story in utils but not in main, as due to type inference I 
do not need to actually specify story type anywhere in main.



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.
    
    
    Run

utils.nim 
    
    
    import story
    
    proc parseStory*(filename: string): Story =
      ...
    
    
    Run

story.nim 
    
    
    type
      Story* = object
        ...
    
    proc `$`*(s: Story): string =
      ....
    
    
    Run

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?

Reply via email to