Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Question about variables in module behavior

$
0
0

I’m trying to understand whether or not this is intended behavior:

I noticed that values in modules aren’t necessarily scoped to their own module. For example, if I call make twice in the module below, the state array will populate for both modules. i intuitively expected for the arrays to be isolated from each other.

module MyModule = {
  type t = array<string>
  let state: t = []

  let make = (foo: string): t => {
    state->Array.push(foo)
    state
  }
}

let a1 = MyModule.make("a")
let _a2 = MyModule.make("b")

Console.log(a1) // ["a", "b"]

This is also an issue for refs. This seems like a bug, but I doubt myself because Melange with Reason has the same behavior when I tested it there as well – fwiw modules in OCaml do not behave in this way


Viewing all articles
Browse latest Browse all 2592

Trending Articles