{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/18466","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/18466/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/18466/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/18466/events","html_url":"https://github.com/JuliaLang/julia/issues/18466","id":176510006,"number":18466,"title":"Proposal: Defer calculation of field types until type parameters are known","user":{"login":"andyferris","id":2974526,"avatar_url":"https://avatars.githubusercontent.com/u/2974526?v=3","gravatar_id":"","url":"https://api.github.com/users/andyferris","html_url":"https://github.com/andyferris","followers_url":"https://api.github.com/users/andyferris/followers","following_url":"https://api.github.com/users/andyferris/following{/other_user}","gists_url":"https://api.github.com/users/andyferris/gists{/gist_id}","starred_url":"https://api.github.com/users/andyferris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyferris/subscriptions","organizations_url":"https://api.github.com/users/andyferris/orgs","repos_url":"https://api.github.com/users/andyferris/repos","events_url":"https://api.github.com/users/andyferris/events{/privacy}","received_events_url":"https://api.github.com/users/andyferris/received_events","type":"User","site_admin":false},"labels":[{"id":97639,"url":"https://api.github.com/repos/JuliaLang/julia/labels/speculative","name":"speculative","color":"999999","default":false},{"id":171886684,"url":"https://api.github.com/repos/JuliaLang/julia/labels/types%20and%20dispatch","name":"types and dispatch","color":"fef2c0","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/JuliaLang/julia/milestones/4","html_url":"https://github.com/JuliaLang/julia/milestone/4","labels_url":"https://api.github.com/repos/JuliaLang/julia/milestones/4/labels","id":96266,"number":4,"title":"1.0","description":"","creator":{"login":"StefanKarpinski","id":153596,"avatar_url":"https://avatars.githubusercontent.com/u/153596?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanKarpinski","html_url":"https://github.com/StefanKarpinski","followers_url":"https://api.github.com/users/StefanKarpinski/followers","following_url":"https://api.github.com/users/StefanKarpinski/following{/other_user}","gists_url":"https://api.github.com/users/StefanKarpinski/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanKarpinski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanKarpinski/subscriptions","organizations_url":"https://api.github.com/users/StefanKarpinski/orgs","repos_url":"https://api.github.com/users/StefanKarpinski/repos","events_url":"https://api.github.com/users/StefanKarpinski/events{/privacy}","received_events_url":"https://api.github.com/users/StefanKarpinski/received_events","type":"User","site_admin":false},"open_issues":147,"closed_issues":78,"state":"open","created_at":"2012-03-15T04:57:43Z","updated_at":"2017-01-19T20:08:58Z","due_on":null,"closed_at":null},"comments":20,"created_at":"2016-09-12T23:24:11Z","updated_at":"2017-01-22T19:37:45Z","closed_at":null,"body":"Currently, we can perform a limited set of logic in the type definition, such as:\n\n``` julia\ntype A\n    a::eltype(Vector{Int})\nend\n```\n\nbut we can't involve a type parameter, such as:\n\n``` julia\ntype B{V <: AbstractVector}\n    a::eltype(V)\nend\n```\n\nAFAICT, at the moment the field types `A.types` is calculated when the type is defined and type parameters are inserted into the correct slots as they become known. \n\nHowever, it would be nice if the types could be calculated by arbitrary inferrable or `@pure` functions. Another simple example (close to my heart) would be:\n\n``` julia\nimmutable StaticMatrix{M,N,T}\n    data::NTuple{M*N, T}\nend\n```\n\nHowever this results in an error that multiplication is not defined for `TypeVar`s. Instead, I need all of this code:\n\n``` julia\nimmutable StaticMatrix{M,N,T,L}\n    data::NTuple{L, T}\n    function StaticMatrix(d)\n        check_params(Val{L}, Val{M}, Val{N})\n        new(d)\n    end\nend\n\n@generated function check_params{L,M,N}(::Type{Val{L}}, ::Type{Val{M}}, ::Type{Val{N}}) # could also be `@pure` in v0.5\n    if L != M*N\n        error(\"Type parameters don't match\")\n    end\nend\n```\n\nand my users need to foist around the redundant `L` paramater when they need to specify a concrete type.\n\nFor abstract types, I'm hoping that inference itself could still be used to come up with a least-pessimistic approximation of each field, or otherwise just use `Any` when that's not possible. If that makes it difficult to avoid regressions, straight types (combinations of types and the relevant `TypeVar`s with `apply_type` but no other functions) could keep functioning as they currently do.\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/274353442","html_url":"https://github.com/JuliaLang/julia/issues/18466#issuecomment-274353442","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/18466","id":274353442,"user":{"login":"vtjnash","id":330950,"avatar_url":"https://avatars.githubusercontent.com/u/330950?v=3","gravatar_id":"","url":"https://api.github.com/users/vtjnash","html_url":"https://github.com/vtjnash","followers_url":"https://api.github.com/users/vtjnash/followers","following_url":"https://api.github.com/users/vtjnash/following{/other_user}","gists_url":"https://api.github.com/users/vtjnash/gists{/gist_id}","starred_url":"https://api.github.com/users/vtjnash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtjnash/subscriptions","organizations_url":"https://api.github.com/users/vtjnash/orgs","repos_url":"https://api.github.com/users/vtjnash/repos","events_url":"https://api.github.com/users/vtjnash/events{/privacy}","received_events_url":"https://api.github.com/users/vtjnash/received_events","type":"User","site_admin":false},"created_at":"2017-01-22T19:37:45Z","updated_at":"2017-01-22T19:37:45Z","body":"I think you're confused about execution environment. `:(() -> $(expr.args[1]))` doesn't create a closure and (by definition) doesn't depend on the environment. That expression also capable of performing any arbitrary side-effect or computation (because it is wrapped in eval), so using the heuristic interpreter (`Base.return_types`) rather than the actual interpreter (`eval`). Using `Base.return_types` should be an huge red-flag in code. Using `eval` in a macro is not generally ideal, but it's not a particular bad practice."}}
{"actor":{"display_login":"vtjnash"}}