Closed antoyo closed 6 years ago
Strictly speaking, each if-then-else (or case-of) expression needs a type annotation:
val tuple = ( if ... then ... else ... ) : (int, int)
Sometimes, the type can be inferred, though.
Ok, thanks. Is it normal that this version does not work as well:
val tuple: (int, int) =
if true then
(1, 2)
else
(3, 4)
?
In the following code, the annotation is for the pattern x (not for e):
val x: T = e
This type annotation means that the type for e is required to be a subtype of T.
Thanks.
Hi. It seems there's an issue with tuples when they are inside an
if
:The previous code triggers this error:
While this code does not:
Thanks to fix this issue.