Open MainShayne233 opened 4 years ago
Also, just wanted to shout out how fun it's been to write Gleam! Other than some of the sharp edges, I get the same level of satisfaction when writing in other statically typed languages like Elm and Rust. Typically, once the compiler is happy, my tests pass on the first run :heart: :heart: :heart:
A smaller reproduction:
fn run(x: Result(Int, Nil)) -> Result(Float, Nil) {
case x {
Ok(_) -> Ok(1.0)
Error(_) -> x
}
}
Here Gleam knows that x
is a Result(Int, Nil)
, so it doesn't allow it to be used as a Result(Float, Nil)
, even if it is in the error case. A smarter compiler would understand that in the error case the type in that branch is Result(anything, Nil)
, but we can't do that yet.
This might be called Flow-Sensitive Type-Inference? I'm not sure.
This would be a nice little improvement, but it is low priority.
Cool! Thanks for the context. The low priority makes sense given that the workaround isn’t too expensive 🙂
:wave: Hey! Me again.
I ran into an issue where the compiler doesn't seem to be able to resolve a value's type when it's generally matched, but can when it's explicitly matched.
Relevant code:
This code results in the following compiler error:
If I change the lines with
error -> error
toError(err) -> Error(err)
, it compiles and works as expected :heart:Commit with broken code: https://github.com/MainShayne233/parcomb/commit/0be0c4e52a135eb4dfe789e0c8e19afa33d73c34
Commit with working code: https://github.com/MainShayne233/parcomb/commit/bc30f5f3127557f871fb329c8c1f5b8d878be0a9
I'd expect the generic matching (i.e.
error -> ...
) to work, but maybe this due to a bit of naivety I have about type checking.P.s. Lemme know if you'd like issues like this to be reported some other way. I don't wanna be an unwanted spammer. :stuck_out_tongue: