I'm trying to make a generic Spline type for my splines in NumericalNim and the
behavior I want is that all splines should have a eval proc acting on a single
float. What I then wanted was to just write one proc that works for all splines
that instead act on a seq[float] and uses the individual splines' eval procs in
a for loop. At first I hard coded my splines like this:
type
SplineType*[T] = CubicSpline[T] or HermiteSpline[T] # Here
CubicSpline*[T] = ref object
X: seq[float]
high: int
len: int
coeffs: seq[array[5, float]]
HermiteSpline*[T] = ref object
X: seq[float]
high: int
len: int
Y: seq[T]
dY: seq[T]
proc eval*[T](spline: CubicSpline[T], x: float): T =
.......
proc eval*[T](spline: HermiteSpline[T], x: float): T =
.......
proc eval*[T](spline: SplineType[T], x: openArray[float]): seq[T] =
result = newSeq[T](x.len)
for i, xi in x:
result[i] = eval(spline, xi)
Run
This compiles and works as expected when I call the eval proc with a
seq[float]. But I want this to work on any Spline I or the user creates in the
future so I found concepts which seemed to fit my needs. But I can't get it to
compile :/ Rather, it never finishes. It feels like it is in some kind of
infinite loop or something. The way I tried to use concepts was this:
type
SplineType*[T] = concept s
s.eval(float) is T
Run
To test this out replace [this
line](https://github.com/HugoGranstrom/numericalnim/blob/613062201ebd560e42a4cab2337b656a8f9b694e/src/numericalnim/interpolate.nim#L5)
with the above concept and then run the test file for interpolate.
> I would very much appreciate any help I could get on this matter :-)