Skip to content
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

Color byref and outref types as mutable #5579

Closed
cartermp opened this issue Sep 3, 2018 · 1 comment
Closed

Color byref and outref types as mutable #5579

cartermp opened this issue Sep 3, 2018 · 1 comment

Comments

@cartermp
Copy link
Contributor

cartermp commented Sep 3, 2018

Consider this horribly imperative program:

type C() =
    let mutable nums = [| 1; 3; 7; 15; 31; 63; 127; 255; 511; 1023 |]

    override __.ToString() = String.Join(' ', nums)

    member __.FindLargestSmaller(target: int) =
        let mutable ctr = nums.Length - 1

        while ctr > 0 && nums.[ctr] >= target do ctr <- ctr - 1

        if ctr > 0 then &nums.[ctr] else &nums.[0]

[<EntryPoint>]
let main argv =
    let c = C()
    printfn "Original sequence: %s" (c.ToString())

    let num = 16
    let v = &c.FindLargestSmaller(num)
    v <- v*2

    printfn "New sequence:      %s" (c.ToString())

    0 // return an integer exit code

// Gives:
// Original sequence: 1 3 7 15 31 63 127 255 511 1023
// New sequence:      1 3 7 30 31 63 127 255 511 1023

Note that v is not mutable - it doesn't need to be, since it's a pointer.

screen shot 2018-09-02 at 23 01 38

Except it's not colored as if it could be mutated like that.

@cartermp cartermp added this to the Unknown milestone Sep 3, 2018
@cartermp cartermp changed the title Color byref types as mutable Color byref and outref types as mutable Sep 3, 2018
@cartermp
Copy link
Contributor Author

cartermp commented Sep 3, 2018

Note that you cannot assign to an inref:

let f1 (x: inref<int>) = x <- 1

So even though it's not the same thing as mutability, since you can only read the value, it's fine if it's not colored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant