{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5270","repository_url":"https://api.github.com/repos/Microsoft/visualfsharp","labels_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5270/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5270/comments","events_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5270/events","html_url":"https://github.com/Microsoft/visualfsharp/issues/5270","id":337215930,"node_id":"MDU6SXNzdWUzMzcyMTU5MzA=","number":5270,"title":"Failed to use Span<'a>.[i] anywhere ","user":{"login":"vasily-kirichenko","id":873919,"node_id":"MDQ6VXNlcjg3MzkxOQ==","avatar_url":"https://avatars2.githubusercontent.com/u/873919?v=4","gravatar_id":"","url":"https://api.github.com/users/vasily-kirichenko","html_url":"https://github.com/vasily-kirichenko","followers_url":"https://api.github.com/users/vasily-kirichenko/followers","following_url":"https://api.github.com/users/vasily-kirichenko/following{/other_user}","gists_url":"https://api.github.com/users/vasily-kirichenko/gists{/gist_id}","starred_url":"https://api.github.com/users/vasily-kirichenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vasily-kirichenko/subscriptions","organizations_url":"https://api.github.com/users/vasily-kirichenko/orgs","repos_url":"https://api.github.com/users/vasily-kirichenko/repos","events_url":"https://api.github.com/users/vasily-kirichenko/events{/privacy}","received_events_url":"https://api.github.com/users/vasily-kirichenko/received_events","type":"User","site_admin":false},"labels":[{"id":295281377,"node_id":"MDU6TGFiZWwyOTUyODEzNzc=","url":"https://api.github.com/repos/Microsoft/visualfsharp/labels/Area-Compiler","name":"Area-Compiler","color":"5319e7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-06-30T13:44:20Z","updated_at":"2018-07-09T15:01:55Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I'm trying to convert examples from https://www.codemag.com/Article/1807051/Introducing-.NET-Core-2.1-Flagship-Types-Span-T-and-Memory-T, namely\r\n```csharp\r\npublic static int SpanSum(Span<byte> data)\r\n{\r\n    int sum = 0;\r\n    for (int i = 0; i < data.Length; i++)\r\n    {\r\n        sum += data[i];\r\n    }\r\n    return sum;\r\n}\r\n```\r\nThe code\r\n```fsharp\r\nlet spanSum (data: Span<byte>) =\r\n    let mutable sum = 0\r\n\r\n    for i = 0 to data.Length - 1 do\r\n        sum <- sum + int (data.[i])\r\n        \r\n    sum\r\n```\r\n\r\n![image](https://user-images.githubusercontent.com/873919/42125707-793c4fba-7c84-11e8-92a2-7cbb0f7c73f4.png)\r\n\r\ntry to add converting to `int`\r\n\r\n![image](https://user-images.githubusercontent.com/873919/42125713-9f2b3ad8-7c84-11e8-8c70-9a64e40e6c2b.png)\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/comments/403510089","html_url":"https://github.com/Microsoft/visualfsharp/issues/5270#issuecomment-403510089","issue_url":"https://api.github.com/repos/Microsoft/visualfsharp/issues/5270","id":403510089,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzUxMDA4OQ==","user":{"login":"cartermp","id":6309070,"node_id":"MDQ6VXNlcjYzMDkwNzA=","avatar_url":"https://avatars0.githubusercontent.com/u/6309070?v=4","gravatar_id":"","url":"https://api.github.com/users/cartermp","html_url":"https://github.com/cartermp","followers_url":"https://api.github.com/users/cartermp/followers","following_url":"https://api.github.com/users/cartermp/following{/other_user}","gists_url":"https://api.github.com/users/cartermp/gists{/gist_id}","starred_url":"https://api.github.com/users/cartermp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cartermp/subscriptions","organizations_url":"https://api.github.com/users/cartermp/orgs","repos_url":"https://api.github.com/users/cartermp/repos","events_url":"https://api.github.com/users/cartermp/events{/privacy}","received_events_url":"https://api.github.com/users/cartermp/received_events","type":"User","site_admin":false},"created_at":"2018-07-09T15:01:55Z","updated_at":"2018-07-09T15:01:55Z","author_association":"CONTRIBUTOR","body":"Note that we document what you can use these for here: https://github.com/fsharp/fslang-design/blob/master/FSharp-4.5/FS-1053-span.md#byreflike-structs\r\n\r\n> * Can be used as function parameters, method parameters, local variables, method returns\r\n> * Cannot be static or instance members of a class or normal struct\r\n> * Cannot be captured by any closure construct (async methods or lambda expressions)\r\n> * Cannot be used as a generic parameters\r\n\r\nAnd I think the key bit is here: **They declare struct types that are never allocated on the heap.**\r\n\r\nThat would imply that any use case where it would be heap-allocated is disallowed. Is that correct, @TIHan / @dsyme? To @zpodlovics's point, this should probably be called out more clearly in the RFC and with some negative examples showing what you **cannot** do."}}
{"actor":{"display_login":"cartermp"}}