What happens now: val xs: Option[Int] = … val ys: List[Int] = … for { x <- xs y <- ys } yield x + y error: type mismatch; found : List[Int] required: Option[?] y <- ys The error's misleading because the real mistake is in x <- xs, and it's the wrong way round.
-
-
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
YES! I've had so many stupid moments where I ended up with the wrong type because `xs` was a different type than I expected!
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Yep. Me too. In my specific case, I often work in the same place in code with futures, event streams, and signals (event streams with caches). It's not difficult to mix them up.
-
Can you show a little code????
End of conversation
New conversation -
-
-
Agreed! And, this would also help those who are learning the language.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
That could be useful.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Explicitly type all the things?
-
Optionally...
End of conversation
New conversation -
-
-
Ah interesting, OCaml has something like this now with its ‘let’ operators, they are defined typically in different modules for different types and you would locally open the appropriate module to use its ‘let’ operators. This indicating which type the expression should have
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.