I have been burned by sentinel values every time. Give me sum types instead. And while I’m piling on, this example makes no sense to me:
proc fib[T: Fibable](a: T): T =
if a <= 2:
result = 1
else:
result = fib(a-1) + fib(a-2)
Integer is the only possible type for T in this implementation, so what was the point of defining Fibable?There can be a lot of different integers, int16, int32 ... and unsigned variants. Even huge BigNum integers of any lengths.
I agree about sentinel values. Just return an error value.
I think the fib example is actually cool though. Integers are not the only possible domain. Everything that supports <=, +, and - is. Could be int, float, a vector/matrix, or even some weird custom type (providing that Nim has operator overloading, which it seems to).
May not make much sense to use anything other than int in this case, but it is just a toy example. I like the idea in general.