0

In C ,

  • every variable denotes a reference, and we can get the reference from a variable by operator &. e.g. if int x=1, then &x is the reference denoted by variable x.

  • every variable is evaluated to the value referred to the reference. e.g. x is evaluated to 1.

In SML,

  • does every variable denotes a reference? E.g. If val y = ref(3), then y denotes a reference which refers to 3. if let val x = 4, what does x denote: 4 or a reference which refers to 4? Can we get the reference denoted by variable x, similarly to & in C?

  • y is evaluated to reference ref 3, and x is evaluated to 4.

Thanks.

Tim
  • 1
  • 141
  • 372
  • 590

1 Answers1

2

A variable binding in SML does not introduce a reference. You cannot get a reference to the x in your example. All references have to be created explicitly, and are first-class values. And only such references are mutable, bindings are not.

In other words, bindings and references are completely independent features in SML.

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72