As many other people, I've tried to write an `Either` type for my own purposes
(peeking into others' solutions). Here is a piece of code that illustrates the
problem I encountered:
type EitherSide = enum
ok, err
type Either[L, R] = ref object
case kind: EitherSide
of ok: left: L
else: right: R
method right[L, R]( r: R ) : Either[L, R] =
Either[L, R]( kind = err, right = r )
proc myfunc() : Either[int, string] =
right( "Not implemented yet!" )
But I get the error message `Error: cannot instantiate: 'L'` from the compiler.
Now, if I was the compiler, I could easily infer the instantiation of `L` as
`int` from the return type of the function `myfunc()`, why can't the `nim`
compiler?