Inferring Locality in OCaml | OCaml Unboxed

Ғылым және технология

This is the fourth video in a series about OCaml’s locals. It covers how the compiler infers what variables can be marked as local_ and it gives a glimpse into some compiler output that you can use to see the inferred modes on variables. I also explain how the compiler infers conversions between locals and globals and introduce *mode-crossing*, showing how ints can be both local and global.
View instructions to get the compiler I use in this video: github.com/janestreet/opam-re...

Пікірлер: 5

  • @paulspl2581
    @paulspl25815 ай бұрын

    Don't know why youtube recommended me this, but really cool video man ! I started out programming with ocaml and this is making me nostalgic ! Your explanations are really clear

  • @huge_letters
    @huge_letters5 ай бұрын

    Is there any difference between these? 1) let f: local_ 'a -> local_ 'a = fun x -> x (* I think I need to put exclave here somewhere - assume the function returns a local *) let x = f "str" (* x is local? *) 2) let f: 'a -> 'a = fun x -> x let x: local_ string = f "str"

  • @RichardEisenberg-JS

    @RichardEisenberg-JS

    5 ай бұрын

    It depends on what you mean by "difference". Your two `f`s (I'll call them f1 and f2) have different types. Because f1's argument is local_, the compiler will try to treat its argument as local. While explored more in the next video, this means that allocations that happen in the argument can be made on the stack, instead of on the heap. (This is good.) In the actual code here, though, the argument is just a constant, so no allocation is necessary. In both cases, `x` is local. (But actually this won't compile as written, because the syntax you've used is for elements of a module, and a variable in a module cannot be local. You don't need exclave_ because there is no allocation in your f.)

  • @huge_letters

    @huge_letters

    5 ай бұрын

    @@RichardEisenberg-JSyeah, sorry - I was mostly interested in the difference for the variable x declared on the 2nd line. It should be local in both cases - so I was curious if there were any advantages to the first option over the second one. Maybe the first option doesn't require a local_ mode on the function parameter for this example, it would probably make my question clearer then - my intuition on all of this isn't that good yet.

  • @VIDEOS-qf5jk
    @VIDEOS-qf5jk5 ай бұрын

    Please sir give me LinkedIn link I can follow you

Келесі