{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/19536","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/19536/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/19536/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/19536/events","html_url":"https://github.com/JuliaLang/julia/issues/19536","id":194382494,"number":19536,"title":"`zero` and `one` for String","user":{"login":"bdeonovic","id":805168,"avatar_url":"https://avatars.githubusercontent.com/u/805168?v=3","gravatar_id":"","url":"https://api.github.com/users/bdeonovic","html_url":"https://github.com/bdeonovic","followers_url":"https://api.github.com/users/bdeonovic/followers","following_url":"https://api.github.com/users/bdeonovic/following{/other_user}","gists_url":"https://api.github.com/users/bdeonovic/gists{/gist_id}","starred_url":"https://api.github.com/users/bdeonovic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdeonovic/subscriptions","organizations_url":"https://api.github.com/users/bdeonovic/orgs","repos_url":"https://api.github.com/users/bdeonovic/repos","events_url":"https://api.github.com/users/bdeonovic/events{/privacy}","received_events_url":"https://api.github.com/users/bdeonovic/received_events","type":"User","site_admin":false},"labels":[{"id":269951426,"url":"https://api.github.com/repos/JuliaLang/julia/labels/strings","name":"strings","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-12-08T16:33:43Z","updated_at":"2016-12-09T05:33:14Z","closed_at":null,"body":"I noticed you can do something like\r\n\r\n```julia\r\njulia> prod([\"*\" for k in 1:3])\r\n\"***\"\r\n```\r\n\r\nbut you might get an error if you try\r\n\r\n```julia\r\njulia> prod([\"*\" for k in 1:0])\r\nERROR: MethodError: no method matching one(::Type{String})\r\n```\r\nWhy was multiplication decided to be the operator on strings which appends them together? Wouldn't addition make more sense? \r\n\r\nWhat do you guys think of introducing \r\n\r\n```julia\r\none(String) = \"\"\r\nzero(String) = \"\"\r\n```\r\n\r\nsince \"zero\" is often defined as a + 0 = a, and \"one\" is defined as a * 1 = 1. This zero then makes sense for the way multiplication is defined for Strings\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/265937498","html_url":"https://github.com/JuliaLang/julia/issues/19536#issuecomment-265937498","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/19536","id":265937498,"user":{"login":"oxinabox","id":5127634,"avatar_url":"https://avatars.githubusercontent.com/u/5127634?v=3","gravatar_id":"","url":"https://api.github.com/users/oxinabox","html_url":"https://github.com/oxinabox","followers_url":"https://api.github.com/users/oxinabox/followers","following_url":"https://api.github.com/users/oxinabox/following{/other_user}","gists_url":"https://api.github.com/users/oxinabox/gists{/gist_id}","starred_url":"https://api.github.com/users/oxinabox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oxinabox/subscriptions","organizations_url":"https://api.github.com/users/oxinabox/orgs","repos_url":"https://api.github.com/users/oxinabox/repos","events_url":"https://api.github.com/users/oxinabox/events{/privacy}","received_events_url":"https://api.github.com/users/oxinabox/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T05:33:14Z","updated_at":"2016-12-09T05:33:14Z","body":"our Strings should be the  [Free Monoid](https://en.wikipedia.org/wiki/Free_monoid) over all characters.\r\nAs a Free Monoid, they should have define their identity element -- the empty string.\r\nAnd since we define our monoid operation using the `*` symbol, we that identity should be called `one`.\r\nThus `one(String) = \"\"` is a good idea, and also `one(::Type{String})`\r\n\r\nShould it further `one{S<:AbstractString}(::Type{S}) = convert(S, \"\")` be defined?\r\n[Like for Numbers](https://github.com/JuliaLang/julia/blob/6a1e339ac1ca24b0d00c1721a1833fb39106c559/base/number.jl#L64)\r\nI'm less sure on that.\r\n\r\n\r\n------\r\n`zero(String)` on the other hand should be left undefined.\r\nIf we went and defined something using the `+` symbol,\r\n then defining `zero` to be that identity would be expected.\r\nAs we are not defining such a operation, it is left free for some user (/package) to do so.\r\nAs such when they do so, they should also be defining `zero(::String)` (not `Base`)\r\n\r\n"}}
{"actor":{"display_login":"oxinabox"}}