I'm working on an experiment using distinct strings to represent biological 
sequences, which come in flavors akin to languages (which I'll use in the 
example below). I want to make a genetic proc that, when not supplied with a 
type, uses the default type. For example:
    
    
    type English = distinct string
    type French = distinct string
    type Language = distinct string
    type OpenLang = Language|English|French
    
    proc readFile[T: OpenLang = Language](filepath: string): T =
      return T("") # dummy
    
    # works
    discard readFile[English]("english.txt")
    discard readFile[French]("french.txt")
    discard readFile[Language]("we_dont_know_what_language_at_compile_time.txt")
    
    # how to make this work?
    discard readFile("we_dont_know_what_language_at_compile_time.txt")
    
    
    Run

I could define an auxiliary function `readFileAs[T]` and make `readFile` 
default to `Language` but that seems inelegant. Is there any way in Nim to make 
this work? 

Reply via email to