3 ms·
I feel we may be arguing without me having properly defined what I meant, so I will try to remedy this. Consider the following code: a, _ := some_computat
by gnuvince 14y ago
I feel we may be arguing without me having properly defined what I meant, so I will try to remedy this. Consider the following code:
a, _ := some_computation_that_may_fail()
b := f(a)
In Go, if there was an error in `some_computation_that_may_fail`, the call to `f` will be made with a undetermined value for `a` and we end up with an undetermined value for `b`. This is why I say that there is a path where we can use `a` even when we shouldn't.
Compare with OCaml:
let Some a = some_computation_that_may_fail () in
let b = f a
First of all, the compiler will warn you that the pattern matching on line 1 is non-exhaustive and will give you an example of a failing case (here, it will simply be `None`). If the programmer ignores that warning and runs the program anyway and the computation executes with an error, the program will fail at the first line, and thus the second function `f` will never be called and `b` will not contain an undetermined value.
I hope this clears up what I meant, I apologize that I wasn't clearer in the first place. Cheers!