Pavel Zaichenkov's answer is of course the best one, but you might be interested in knowing the exact cause of the error. Namely, when you have
if y == x then i
without a corresponding else
expression, the whole expression is treated as
if y == x then i else ()
where ()
is the only value of the type unit
(and not uint
), which is the type of expressions that are evaluated for their side effects only. Since both branches of the if
must have the same type, i
is deemed to have type unit
also. Then, when type-checking the third branch of the pattern-matching, you try to add i
and 1
, which means that i
should have type int
, hence the type error.