Understanding OCaml Locals as a Mode (with Sub-Moding) | OCaml Unboxed

  Рет қаралды 1,619

Jane Street

Jane Street

Күн бұрын

Пікірлер: 4
@huge_letters
@huge_letters Жыл бұрын
How would something like let y = "string" in let local_ z = y in y work? Doesn't this kinda escape its region - but y is global so it should be fine but it's not in terms of z being local also being equal to y? What about if it's not just a string but a ref?
@RichardEisenberg-JS
@RichardEisenberg-JS Жыл бұрын
Global/local is something that applies to expressions and values, not memory locations. So in your example, z is local (and would not be allowed to escape) and y is global. So returning y is just fine -- even if y and z are aliased in memory. The same is true for a mutable reference: a local variable can be aliased with a global, and the global one is allowed to escape.
@huge_letters
@huge_letters Жыл бұрын
@@RichardEisenberg-JS I see I was just thinking in terms of your previous example with a file handle. Say, a function creates and returns a file handle - wouldn't it be able to retain it through those means? Or it then just guarantees that the ref is local, not the underlying value? Anyways I'm glad to be learning OCaml during such resurgence :)
@RichardEisenberg-JS
@RichardEisenberg-JS Жыл бұрын
@@huge_letters There's a subtlety in the way that question is phrased, mentioning returning the file handle. If a function returns a file handle, then the handle can't be local -- there's no way to control where it will end up (as you rightly surmise). But we can still protect file handles by using a callback (or continuation, if you prefer that term): `with_file : string -> (local_ handle -> 'r) -> 'r`. Once something is local, it can't be made global, so that file handle will be protected.
Inferring Locality in OCaml | OCaml Unboxed
22:27
Jane Street
Рет қаралды 1,5 М.
Unboxed Types for OCaml
47:18
Jane Street
Рет қаралды 7 М.
УЛИЧНЫЕ МУЗЫКАНТЫ В СОЧИ 🤘🏻
0:33
РОК ЗАВОД
Рет қаралды 7 МЛН
The Lost World: Living Room Edition
0:46
Daniel LaBelle
Рет қаралды 27 МЛН
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН
Writing an interpreter... in OCaml?!?
17:10
TJ DeVries
Рет қаралды 42 М.
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 1 МЛН
James Beilby (Banking Industry): An Algo Execution System in Rust
10:32
Understanding Recruitment
Рет қаралды 7 М.
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Рет қаралды 361 М.
Stack Allocation with Locals in OCaml | OCaml Unboxed
11:07
Jane Street
Рет қаралды 1,8 М.
Vim Tips I Wish I Knew Earlier
23:00
Sebastian Daschner
Рет қаралды 88 М.
How OCaml Represents Values in Memory
12:43
Jane Street
Рет қаралды 6 М.
What P vs NP is actually about
17:58
Polylog
Рет қаралды 147 М.
I implemented Goto in OCaml
38:41
Tsoding Daily
Рет қаралды 43 М.
Rust With GC??!? Ocaml's new Features
53:56
ThePrimeTime
Рет қаралды 47 М.
УЛИЧНЫЕ МУЗЫКАНТЫ В СОЧИ 🤘🏻
0:33
РОК ЗАВОД
Рет қаралды 7 МЛН