Hello, guys!
type
Maybe = tuple or object
Some[T] = tuple
value: T
None = tuple
proc either[T](m: Maybe, alternative: T): T =
if (type(m) == type(Some)):
return m.value
else:
return alternative
proc main(): void =
var m: Some[int] = (value: 10)
var t: int
t = either(m, 11)
echo $t
What wrong with this code? If I compile this, the error is
maybe.nim(19, 13) Error: type mismatch: got (Some[system.int], int
literal(11))
but expected one of:
proc either[T](m: Maybe; alternative: T): T
changing last two lines to
t = either[int](m,11)
echo $t
leads to
maybe.nim(19, 13) Error: cannot instantiate: either[int]; got 1 type(s) but
expected 2
If I remove main proc at all then it compiles without error, so I expect
declaration of either proc is correct