title: Type classes in Nim
body: <p>I am trying to make a simple use of typeclasses in Nim. Please, keep in mind that I only have been using Nim since this morning, so I may have been doing something stupid.</p>
  
  <p>Anyway, I would like to define a pseudorandom generator that produces a stream of values of type <code>T</code>. Sometimes <code>T</code> is numeric, hence it makes sense to know something about the minimum and maximum values attainable - say to rescale the values. Here are my types</p>
  
  <pre><code>type
    Generator*[T] = generic x
      next(var x) is T
  
    BoundedGenerator*[T] = generic x
      x is Generator[T]
      min(x) is T
      max(x) is T
  </code></pre>
  
  <p>I also have such an instance, say <code>LinearCongruentialGenerator</code>.</p>
  
  <p>Say I want to use this to define <code>Uniform</code> generator that produces float values in an interval. I have tried</p>
  
  <pre><code>type Uniform* = object
    gen: BoundedGenerator[int]
    min_p: float
    max_p: float
  
  proc create*(gen: BoundedGenerator[int], min: float, max: float): Uniform =
    return Uniform(gen: gen, min_p: min, max_p: max)
  </code></pre>
  
  <p>I omit the obvious definitions of <code>next</code>, <code>min</code> and <code>max</code>.</p>
  
  <p>The above, however, does not compile, due to <code>Error: 'BoundedGenerator' is not a concrete type</code></p>
  
  <p>If I explicitly put <code>LinearCongruentialGenerator</code> in place of <code>BoundedGenerator[int]</code>, everyting compiles, but of course I want to be able to switch more sophisticated generators.</p>
  
  <p>Can anyone help me understand the compiler error?</p>