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

Unsoundness of mutable references #1

Open
elpinal opened this issue Nov 23, 2020 · 0 comments
Open

Unsoundness of mutable references #1

elpinal opened this issue Nov 23, 2020 · 0 comments

Comments

@elpinal
Copy link
Owner

elpinal commented Nov 23, 2020

It has turned out that mutable references in Bright ML is unsound. The following code is adopted from SML code in http://mlton.org/ValueRestriction and causes Bright ML crash.

val f 'a _ =
   let
      module R = Ref.Make {type t = option 'a}
      val r = R.make None
   in
   fun x ->
      let
         val y = R.get r
         val _ = R.set r $ Some x
      in
        match y with
          | None   -> x
          | Some y -> y
        end

val f = f ()

val _ = f 13
val _ = String.`<>` "" $ f "foo"

I had thought generative functors would rescue the interaction between polymorphism and mutable references, but that's wrong.

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

No branches or pull requests

1 participant