-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typing of outputs of the standard library functions #512
Comments
@Gvaihir this is an interesting edge case that I personally have not come across. Type coercion can lead to a bit of a mess IMO as @jdidion (and @orodeh before him) has mentioned in the past. Allowing for these automatic type coercions is at once handy to the user in most cases, and extremely frustrating in all other situations. In the first case, do you know what the type of In general though, you do raise an interesting point about type coercion in situations where there is no explicit LHS type (as in a scatter). This is very much so the "Best Guess" approach of the engine to basically return the compatible types. I wonder if we could allow or even enforce explicit typing in the scatter (Pair[Pair[Int, Int], String?] nested_pair in zip(zip(foo, bar), lol)) {
String? opt = nested_pair.right
String nonOpt = select_first(nested_pair.right,"")
} |
Thanks for the reply @patmagee! As to your suggestion - I would propose to consider it. Maybe not in |
@Gvaihir given that this was a bug in the implementation, do you think it is worth keeping this issue open or should we potentially start another discussion around explicitly typing outputs in operations like scatter? |
@patmagee - I started the issue exactly to discuss explicit typing of stdlib functions. My OP attempts to give an example where this may be relevant. Indeed - the implementation was fixed, but that bug was not at the center of my question. I have the following suggestions for moving forward:
|
The parameter and return types of the standard library functions are given as explicitly as possible. Some functions are generic and thus the return type depends on the input type(s). In this case, the types are given using generic parameters, but the intention is for the engine to enforce the data types. In the following example, the return type of
If you have specific examples of standard library functions where a parameter or return type is not explicit (or explicit enough) please re-open this issue and add that information. Thanks |
I tried to revive #373 but it might not be bumped. So here's a new issue.
I'd like to have some clearance on type coercion of the inputs/outputs from the standard library functions.
On the one hand - all inputs and outputs must be typed.
But I do see some use cases where the following syntax is used:
I could not find any elaboration on such cases in the spec (mostly I see it in the users' code), and I think this is a bit contradicting the static typing requirement. In general though seems these examples compile and run, but we start to see coercion problems when nesting such functions and applying them to optional types. Like this:
In this case we see the problems of coercion for values of
lol
which were evaluated tonull
, throwing exceptions at runtime. If we declare and type the outputs - all fine, no exceptions:We can solve this in dxCompiler and allow such scenarios, but isn't this in the realm of automatic type coercion and contradictory to strong/static typing of the language?
Could you provide more explicit guidance on typing the inputs/outputs for the standard library functions in the language spec? Should typing of inputs/outputs of the standard library functions be enforced?
The text was updated successfully, but these errors were encountered: