-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
function types #210
Comments
As stated, issue looks like a theoretical problem. An example where it matters: map decides that the type is simply ASCIIString after the first element. Backtrace is also suboptimal: invalid ASCII sequence |
Thanks. This is very much not a theoretical problem; see #670. |
I am currently rewriting some Julia code and got biten by this again. Fix is easy, but understanding what goes on... Is it a good idea to have verbose messages for such cases? It could explicitly say that map chose wrong type for the list based on the first element and that explicit type-cast is needed. This would reduce cost for user from "Wait What Why?!" to "Oh, a minor glitch, nevermind", as far as I understand. |
I also have a use case where it would be very helpful to be able to access type inference of an expression programmatically. |
Bump |
Is this the kind of syntax that would be Julian? function map{S,R}(f::S->R, arr::Array{S,1})::Array{R,1} # return type just for fun
# or:
function map{S,R}(f::((S)::R), arr::Array{S,1})::Array{R,1} |
It seems to me this is the most important that is holding back Julia. Everywhere I turn this seems to surface - is there anyone actively working on function types? Of course there has to be a "no. 1" item with anything. Not to denigrate Julia at all (I love multiple dispatch).. but onwards and upwards and all that :) ps. my no. 2 & 3 would be triangular dispatch and return types! |
I think that the ability to query types at runtime would be extremely useful, e.g. return_type(*, Int, Int) == Int
return_type(*, Int, Float64) == Float64
return_type(my_func, Int) == Union(ASCIIString, Nothing) As far as I know, Julia has this information already – exposing it would solve the Also, it might be helpful if functions like |
There used to be an unexported function The problem with querying return type information from type inference is that it's too volatile. Changes in type inference may change which type you get. Changes in one place in the code may cause cascading changes in types inferred elsewhere. Comprehensions currently exploit type inference to pick a return type, but as I understand it the desire is to move away from this, not to do it in more places. See also Stefan's comments in #670. |
How about querying If you need a particular return type (e.g. for dispatch), it makes sense to specify it explicitly: There could still be edge-case problems, but I imagine they'd be rare – especially as type inference matures. |
Out of curiosity, what's the core team's stance on this? I see that other issues are being deduped to this, but I'm wondering whether this is undecided, is accepted and literally targeted to 1.0, or more abstractly targeted to sometime in the indefinite future. |
Well, we don't know what this issue means exactly. The milestone is not real yet.
There are a couple ways to get (2), and function types don't necessarily have to be part of it. Function types and generic functions are like oil and water. There are certainly a few ways we could use them, but none are an obvious fit for multiple dispatch. |
It would also be good to get a better result type from |
Latest discussion in #10269 |
@JeffBezanson i think you get the honor of closing this one now |
@vtjnash – I think you may be misunderstanding the intended meaning of this issue. Yes, functions are types now in the Julia sense, but not in the sense that static languages generally mean it. I think the conclusion is that we cannot do this and this issue is superseded by a combination of #1090 and #7258 and |
I'am a little bit confused about: What is the current state of typed functions?
The latter would be better as we can filter out functions that we do not want.
|
Neither, they have their own type but they don't and can't (as it doesn't make any sense) to give you argument and return types. |
Does it have to do something with methods versus function, where a method has only one argument type tuple and one return type and functions multiple argument type tuples and return types? |
That's part of the issue, yes, but it's mostly that the language is dynamically typed so functions do not have meaningful return types (other than the types of values they actually return at run time). |
Disregarding the multiple method problem, mabye, a special function type could be created for functions in which the types are hardcoded by the user? For instance, something like StaticFunction{Tuple{Int64,Float64},Int64} |
(cherry picked from commit ef37aa7d4f68e47f74346da40daa671528385755)
(cherry picked from commit ef37aa7d4f68e47f74346da40daa671528385755)
Is this still a thing? It seems closable as moot. |
Closing since we aren't going to change this. |
This happens when the call is module-scoped. Fixes JuliaDebug/Debugger.jl#141
Then just settle for map returning a type of the map function as the output array type.
The text was updated successfully, but these errors were encountered: