t7734.nim 369 B

1234567891011121314151617181920
  1. type
  2. Foo[T: SomeFloat] = object
  3. learning_rate: T
  4. Bar[T: SomeFloat] = object
  5. learning_rate: T
  6. momentum: T
  7. Model = object
  8. weight: int
  9. FooClass = Foo or Bar
  10. proc optimizer[M; T: SomeFloat](model: M, _: typedesc[Foo], learning_rate: T): Foo[T] =
  11. result.learning_rate = learning_rate
  12. let a = Model(weight: 1)
  13. let opt = a.optimizer(Foo, 10.0)