> Wait ... what? That looks like the kind of feature that saves a couple of key
> strokes for the end user
No, this is actually quite an important feature! Imagine a function
constructing an error return for `Either` \- consider `return Either.Le(42)` \-
there is no need to repeat the full either type here because all information
can be deduced by the compiler - now, place this in a template:
template makeError(code: int): Either.Le[string] =
Either.Le(codeToString(code))
proc myFunction(): Either[string, int] =
let code = readFile(myVar)
if isError(code):
return makeError(code)
return Either.Ri(myVar.toInt())
Run
In the above, you can see how it would be pointless to repeat the full Either
type all the time - in this case it's a return but the "lhs" could be a
variable, ie `let myeither: Either[string, int] = Either.Le("test")` \- this is
critical for building reusable utilities that complement a sum type - notably,
something like `makeError` is universal to all `Either`:s that have a string on
one side and providing the right hand type would be both inconvenient, clunky
and above all, redundant/pointless.
When talking about exploiting the strucutural advantages of having only one
tag, this is a good example.