It should not forbit it but allow it. Please notice that generics are almost 
replaceable by () operator (it should be replaceable by [] operator but then it 
only works when called explicitly, not by operator syntax):
    
    
    template Sth(t: typedesc = int): typedesc =
      type `Sth t` = object
        value: t
      `Sth t`
    
    var x: Sth(int)
    var y: Sth(float)
    var z: Sth()
    echo x
    echo y
    echo z
    

Which is a beautiful example for the fact that higher order types are just 
endofunctors on types.  And also, that's how generic data structures are built 
in Zig.

Anyway, the analogue should also be valid:
    
    
    type Sth[T = int] = object
      value: T
    
    var x: Sth[int]
    var y: Sth[float]
    var z: Sth[]  # should be valid
    echo x
    echo y
    echo z
    

But sadly, it's not. 

Btw. actually, the template-based approach is much more powerful as it can 
provide things that have no analogue in Nim's types: 
    
    
    template Sth(t: typedesc = int): typedesc =
      when t is int: int
      elif t is float: float
      else: {.error: "Only ints or floats, please".}; void
    
    var x: Sth(int)  # x is int
    var y: Sth(float)
    echo x
    echo y
    

when allows to customize concrete types but only for objects. Template-based 
approach allows any type.

Reply via email to