{"action":"created","issue":{"url":"https://api.github.com/repos/orange-lang/orange/issues/6","labels_url":"https://api.github.com/repos/orange-lang/orange/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/orange-lang/orange/issues/6/comments","events_url":"https://api.github.com/repos/orange-lang/orange/issues/6/events","html_url":"https://github.com/orange-lang/orange/issues/6","id":91854866,"number":6,"title":"Syntax for generic functions should be consistent ","user":{"login":"rfratto","id":630212,"avatar_url":"https://avatars.githubusercontent.com/u/630212?v=3","gravatar_id":"","url":"https://api.github.com/users/rfratto","html_url":"https://github.com/rfratto","followers_url":"https://api.github.com/users/rfratto/followers","following_url":"https://api.github.com/users/rfratto/following{/other_user}","gists_url":"https://api.github.com/users/rfratto/gists{/gist_id}","starred_url":"https://api.github.com/users/rfratto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rfratto/subscriptions","organizations_url":"https://api.github.com/users/rfratto/orgs","repos_url":"https://api.github.com/users/rfratto/repos","events_url":"https://api.github.com/users/rfratto/events{/privacy}","received_events_url":"https://api.github.com/users/rfratto/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/orange-lang/orange/labels/language%20change","name":"language change","color":"5319e7"},{"url":"https://api.github.com/repos/orange-lang/orange/labels/proposal","name":"proposal","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-29T16:48:21Z","updated_at":"2015-06-29T16:56:42Z","closed_at":null,"body":"Since implicitly defined variables have been removed, the syntax for generic functions is inconsistent with the rest of the language now. \r\n\r\nThe current idea is this: \r\n\r\n``` \r\ndef add(var a, var b) \r\n    return a + b\r\nend \r\n\r\nadd(3, 5.0) # calls add(int, float)\r\n``` \r\n\r\nThis function would create a generic function where each parameter can have its own unique type. \r\nIf you wanted to restrict each parameter to be the same type, this is the current idea for that:\r\n\r\n``` \r\ndef add<T>(T a, T b)\r\n    T sum = a + b \r\n    return sum\r\nend \r\n\r\nadd(3, 5.0) # invalid: no function add(int, double) found \r\nadd<int>(3, 5.0) # valid: 5.0 casted to int \r\n```\r\n\r\nThe type of `T` in this example is assumed to be any type name or class. Constant values can be assignable, too: \r\n\r\n``` \r\ndef add_and_mult<T, T s>(T a, T b) \r\n    return (a + b) * s\r\nend \r\n\r\nadd_and_mult<int, 5>(3, 5) # returns 40\r\n``` "},"comment":{"url":"https://api.github.com/repos/orange-lang/orange/issues/comments/116760574","html_url":"https://github.com/orange-lang/orange/issues/6#issuecomment-116760574","issue_url":"https://api.github.com/repos/orange-lang/orange/issues/6","id":116760574,"user":{"login":"rfratto","id":630212,"avatar_url":"https://avatars.githubusercontent.com/u/630212?v=3","gravatar_id":"","url":"https://api.github.com/users/rfratto","html_url":"https://github.com/rfratto","followers_url":"https://api.github.com/users/rfratto/followers","following_url":"https://api.github.com/users/rfratto/following{/other_user}","gists_url":"https://api.github.com/users/rfratto/gists{/gist_id}","starred_url":"https://api.github.com/users/rfratto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rfratto/subscriptions","organizations_url":"https://api.github.com/users/rfratto/orgs","repos_url":"https://api.github.com/users/rfratto/repos","events_url":"https://api.github.com/users/rfratto/events{/privacy}","received_events_url":"https://api.github.com/users/rfratto/received_events","type":"User","site_admin":false},"created_at":"2015-06-29T16:56:42Z","updated_at":"2015-06-29T16:56:42Z","body":"The functionality behind defining specific generic types is more complex than just using `var`. At the very least, the typeless generic parameters can be changed to require `var` first, before the other feature is implemented. "}}