Rust With GC??!? Ocaml's new Features

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024
  • Recorded live on twitch, GET IN
    / theprimeagen
    Reviewed article: blog.janestree...
    By: Max Slater | / the_numbat
    MY MAIN YT CHANNEL: Has well edited engineering videos
    / theprimeagen
    Discord
    / discord
    Have something for me to read or react to?: / theprimeagenreact
    Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
    turso.tech/dee...

ความคิดเห็น • 128

  • @billybest5276
    @billybest5276 10 หลายเดือนก่อน +99

    Funny that you joke about being an educational channel. I been noticing lately I get a lot of useful nuggets from watching more casual videos on about programming. I never know what I am going to find but when you do find it. Its like you knew that's what you needed to find and can immediately put it to practice.

    • @ThePrimeTimeagen
      @ThePrimeTimeagen  10 หลายเดือนก่อน +35

      :)

    • @zedekai9456
      @zedekai9456 10 หลายเดือนก่อน +6

      @billybest5276 Actually! Constantly I'm learning tiny nuggets that unlock understanding. Often things i didn't realise I didn't quite understand.

    • @jrohit1110
      @jrohit1110 10 หลายเดือนก่อน

      This

    • @restrictednkarki5707
      @restrictednkarki5707 10 หลายเดือนก่อน +3

      The best part is when they're discussing concepts and now i gotta lookup that concept and stuffs. This does not happen in actual educational videos!

    • @needsloomis7164
      @needsloomis7164 10 หลายเดือนก่อน +1

      Once you get past syntax, formulae, and patterns, the rest is all experience, philosophy, and nuanced opinion/discovery.
      The classroom is great for the former, but open forums and casual discussions are where you get into the meat and potatoes of the latter.

  • @scosminv
    @scosminv 10 หลายเดือนก่อน +12

    I love how OCaml gets inspiration from Rust after Rust got inspiration from OCaml :). I can now see how OCaml has some unique advantages over F#.
    Thanks for your continued focus on OCaml, guys!

  • @SeySvK
    @SeySvK 10 หลายเดือนก่อน +50

    html is faster

    • @arctan2
      @arctan2 10 หลายเดือนก่อน +3

      based

    • @SimGunther
      @SimGunther 10 หลายเดือนก่อน +9

      It can't render what it can't parse, so the error handling for it is blazingly fast!

  • @Tomyb15
    @Tomyb15 10 หลายเดือนก่อน +10

    Haskell has (experimental) support for linear types, though they are not the same as the affine types of Rust.
    Hopefully one day linear types in haskell will be extended to affine types. Once you have linear types, affine types shouldn't be too much extra work (as far as I understand)
    Not to mention that a lot of these things can also be done in haskell with indexed monads, like making sure a file descriptor is closed before you finish or leave a computation.
    You can also do internal mutability with the ST monad, etc.

    • @reo101
      @reo101 10 หลายเดือนก่อน +2

      Ye, Linear types are just Affine types + a lower bound for usage

    • @linusziegler2413
      @linusziegler2413 หลายเดือนก่อน

      Ever tried working with the STD monad?

  • @jancartman321
    @jancartman321 10 หลายเดือนก่อน +6

    I'm curious about the recent complains about Rust. I haven't experienced Arc hell or lifetime explosion for my usual web apps. I would love to see Prime giving some real world examples for Go vs Rust vs Ocaml.

    • @kriscarr2442
      @kriscarr2442 10 หลายเดือนก่อน +2

      I haven't seen Arc hell, but I have seen lifetime explosions in web apps when later down the line a field in a struct changes to be something that requires a lifetime.
      In a recent case it was a field that was initially a concrete struct with an associated function becoming a dyn trait object, or vector of them, like a Vec or something similar. Then everywhere that takes or injects this struct such as middleware extractors now needs this lifetime adding, including whatever was initially building this struct, then anything that uses that and so on. When it's on things like state for web apps you can get away with static but this is not always the case depending on what it is, such as something that's being built up in middleware and injected into the request context for further down.
      It's a quick and simple refactor, I find it to be a seconds vs minutes gripe, but it can result in a lot of lifetime adding to signatures, impl blocks etc for the sake of what was initially interpreted as a simple change. That kind of "simple" change in other languages, essentially changing a field type from a "struct" to an "interface", is actually significant under the hood, Rust just makes you realise how significant as the lifetime can't/won't be automatically inferred anymore.
      The only real actual "issue" I can see with it is the amount of git merge conflicts it can cause in teams as you can end up changing a lot of seemingly unrelated code to your original business logic requirement requiring the change, or "breaking" code wanting to come in from other PRs. That's what desk-nunchucks are for though.

    • @Caellyan
      @Caellyan 9 หลายเดือนก่อน

      ​@@kriscarr2442 Why not put that dyn into `Box` or a `Rc`/`Arc` if it needs to be shared? It would end up on heap anyway due to `Vec`. Alternatively something like `any_vec` crate would be a nice fit to retain a single vtable deref.
      I use a rule of thumb for references and it's: "Should my `StructA` care about this lifetime existing?". So for something like `Reader`, it cares about the source; something like `House` shouldn't have a lifetime because one of the inhabitants might have a shared car - car goes in `Rc`.

  • @teej_dv
    @teej_dv 10 หลายเดือนก่อน +9

    ocaml btw

  • @SyamaMishra
    @SyamaMishra 10 หลายเดือนก่อน +10

    I'd love a video comparing writing a program in rust with and without cloning.

    • @user-uf4lf2bp8t
      @user-uf4lf2bp8t หลายเดือนก่อน

      I mean you can just try doing it. It comes up in essentially every program.

  • @twenty-fifth420
    @twenty-fifth420 10 หลายเดือนก่อน +3

    *pets the Prime’s OCaml* 🐫
    “Wow, thats a good camel right there. It takes a function like no problem! Thats a good camel right there!” 😻

  • @simonfarre4907
    @simonfarre4907 10 หลายเดือนก่อน +8

    I love OCaml-users who think OCaml has more industry adoption than Haskell, its cute really. Especially since it only requires a 15 second google to find out that the financial industry has an order of magnitude more adoption of Haskell. Which is hilarious in and of itself, because that means that 10 companies use Haskell. Rust, which hasn't even been around half as long as either, has more adoption. That's a sad state of affairs. 😅

  • @NicOesterby
    @NicOesterby 10 หลายเดือนก่อน +3

    So it's like a local opt-in to Rust's safety features. Interesting. Though, as far as I can tell, you still get some function coloring. If you make a function parameter unique, then you might have to track down all calls to the function and ensure the uniqueness of the argument, potentially making more parameters unique or exclusive. If they manage to infer these modes, though, it's gonna be huge.

  • @jeremycoleman3282
    @jeremycoleman3282 10 หลายเดือนก่อน +8

    wasn't rust originally written in ocaml?

  • @saymehname
    @saymehname 10 หลายเดือนก่อน +8

    Wow you know I’m only a little interested in rust but I’ve always wanted to try a taste of the functional koolaid. I think I will join you for Advent of Code this year in OCaml

    • @computerfan1079
      @computerfan1079 10 หลายเดือนก่อน

      Same here

    • @asdf1616
      @asdf1616 4 วันที่ผ่านมา

      Did you try out OCaml?

  • @aoeuable
    @aoeuable 10 หลายเดือนก่อน +2

    Now things are coming full circle, rust's memory management is based on research on region-based memory management that was done as a ML dialect, back in 1995.

  • @celiacasanovas4164
    @celiacasanovas4164 10 หลายเดือนก่อน +4

    So what's more complicated: explicit borrowing and explicit lifetimes, or a hundred modifiers? It's a tradeoff I guess but now I appreciate Rust more. Also: F# is awesome and they should incorporate some of the new OCaml stuff.

    • @muhwyndham
      @muhwyndham 10 หลายเดือนก่อน +1

      GC + Mem. Arena is all I need.
      I'm noob though so I really like go.

    • @celiacasanovas4164
      @celiacasanovas4164 10 หลายเดือนก่อน

      @@muhwyndham yeah, Arenas are a great idea. I'm not a fan of how imperative Go is but it's a very cool language.

  • @remissio42
    @remissio42 10 หลายเดือนก่อน +9

    While i understand your issues with:
    - coloring
    - futures being lazy
    - ownership & lifetimes
    I personally do like the explicitness everywhere in Rust.
    Futures running before i tell them to are a headache for me. I like working with lifetimes and ownership. And i don't mind having colored async functions when they e.g. use async internally since it gives me a heads-up for what is happening "down below". Though the situation with multiple runtimes and tokio being a de-facto standard hurts me - i prefer zigs way of providing the async runtime.
    Love your content! I'm regularly learning a lot from you. Your opinion on topics is a valuable factor in quite a few decisions i have to make in my job & personal projects.
    Thank you Prime!

    • @taragnor
      @taragnor 10 หลายเดือนก่อน +2

      The concept of lifetimes is good in principle, but the explosions of lifetime required errors you get when you add one anywhere is truly brutal. It's the main area Rust needs improvement. What if the compiler could just keep trying different lifetime requirements until the code worked, maybe putting up a warning if one of your variables needed a static lifetime as a result so you're not eating too much memory.
      Lifetimes are just handled as a total pain in the ass. Like if I create a struct containing a reference, it forces me to put a lifetime just to tell it that the struct's lifetime has to be shorter than the reference's lifetime, so it can't hold a dead reference. This is 100% a thing the compiler should be able to figure out on its own.

    • @maniacZesci
      @maniacZesci 10 หลายเดือนก่อน +1

      @@taragnorSure, but what if your struct has two or more references? Do they have the same lifetime or different ones? Also he is saying that Rust's "fearless concurrency is just Arc> which is not true. Rust's fearless concurrency are Send and Sync traits (possibly other mechanism's too, not a Rust expert) by which Rust can check at a compile time that you wont have data races.

    • @remissio42
      @remissio42 10 หลายเดือนก่อน

      ​@@maniacZesci you are correct with Arc not being the only option. There are for example multiple channel implementations within the tokio::sync module and within the crossbeam crate which i have used. The choice between those depends on if the project is async or not. As opposed to golang we get specialized channel implementations for different use cases (e.g. mpsc, mpmc, oneshot).

    • @taragnor
      @taragnor 10 หลายเดือนก่อน

      @@maniacZesci The rust complier can already tell if you have lifetime problems, that's part of what makes it so good at spotting errors. All I'm saying is that it could just fill in a lifetime that makes your code work. Essentially just try a few different lifetimes to see if the code compiles, and if it only works with a static lifetime then give a compiler warning. I understand if you're writing some code for a library, you'd probably still have to do them yourself, because you don't have all the code, but if you're writing a complete executable, the Rust compiler has all the code and a complete picture of the program. If there exists a set of lifetimes that work for that program, it should just be able to auto fill them in in a way that eliminates the compilation error (assuming your program isn't doing anything totally unsound that'd make that it impossible to set a lifetime).

    • @maniacZesci
      @maniacZesci 10 หลายเดือนก่อน

      @@remissio42 also atomic types with Ordering enum for lock-free concurrency but those are not simple to use.

  • @jackdeespadas
    @jackdeespadas 10 หลายเดือนก่อน +5

    If Prime and TJ would kiss in the mouth their facial hair wouldn't touch. It's like they complete each other, and a van dyke (beard.)

  • @matetheg
    @matetheg 10 หลายเดือนก่อน +4

    "It runs and maybe like someone makes money off of it" 🔥

  • @TakinProfit
    @TakinProfit 10 หลายเดือนก่อน +7

    When I see this type of stuff, I wonder why F# is never mentioned?

    • @natescode
      @natescode 10 หลายเดือนก่อน +12

      Because Prime hates Microsoft

    • @maamardli
      @maamardli 10 หลายเดือนก่อน +4

      F# is the perfect balance between functional and object oriented... I think if it wasn't maintained by Microsoft it would have been more popular.

    • @55sombreroman
      @55sombreroman 10 หลายเดือนก่อน +2

      More like F Shart. Gottem

    • @ivanjermakov
      @ivanjermakov 10 หลายเดือนก่อน +4

      Exceptions in FP, what a tragedy.

    • @metaltyphoon
      @metaltyphoon 10 หลายเดือนก่อน +8

      Because he hates Microsoft so much but still relies on windows for streaming, typescript for work, and GitHub for SCM.
      There is no logical sense here.

  • @stysner4580
    @stysner4580 10 หลายเดือนก่อน +4

    11:06 isn't that the point of implicit Copy in Rust though?! Where if it's trivial to copy it'll just do that? To me the whole point is that in Rust you might need to be verbose all the time, but if too much stuff is opt-in someone is bound to mess it up and you're left with the same problems again.

  • @thistent
    @thistent 10 หลายเดือนก่อน +2

    This looks a lot like reference capabilities in Pony.

    • @everyhandletaken
      @everyhandletaken 10 หลายเดือนก่อน

      That’s developed by Ginuwine, right?

  • @replikvltyoutube3727
    @replikvltyoutube3727 10 หลายเดือนก่อน +3

    Firstly OCaml for AOC2023 FTW!
    This is a healthy language competition, just like antimonopoly in business, both are learning from each other and evolve to higher level. Which, the OCaml wasn't that low level to begin with.
    Are they both eventually going to evolve into Haskell? 😂

  • @dforj9212
    @dforj9212 10 หลายเดือนก่อน +6

    You should look at Haskell's linear types 👀

  • @redcrafterlppa303
    @redcrafterlppa303 10 หลายเดือนก่อน +4

    1:00 I don't really get what people are talking about. I literally never use clone and I don't see how it would help in many situations. A &mut is all you need 90% the time anyway.

    • @stysner4580
      @stysner4580 10 หลายเดือนก่อน

      I feel the same way. If you use clone a lot you should rethink the architecture of your program. You can get away with &mut fn parameters passing stuff around just fine. The same with the whole "Arc" and "

  • @user-ue5bx8sp6r
    @user-ue5bx8sp6r 10 หลายเดือนก่อน +1

    Have you ever played with ReasonML? It seems more approachable, does it share the same features? It's built on top of ocaml, right?

    • @draakisback
      @draakisback 10 หลายเดือนก่อน

      Reasonml I was a mess. Now I think it's just called re-script which is fine I suppose but it leans very heavily into the JavaScript syntax which is not easier.

  • @oraqlle
    @oraqlle 10 หลายเดือนก่อน

    Funny they say TJ might actually build something that’s gets to production using OCaml yet Rust’s compiler was first written in OCaml.

  • @CheaterCodes
    @CheaterCodes 10 หลายเดือนก่อน

    I like the statement of "Does this mean i don't have to go and put lifetimes everywhere?"
    I'm pretty sure that's wrong: If you run into a situation where you would need a lifetime (a function returning a reference) you just can't do it.
    At least that's how i understand it. More like C++ references maybe.

  • @complexity5545
    @complexity5545 10 หลายเดือนก่อน

    I probably will never use OCaml again, but its cool that a newer gen is refactoring OCaml.
    It's going to end up being Haskell.

  • @aredrih6723
    @aredrih6723 10 หลายเดือนก่อน

    I'm curious how this feature will work with partial application. Then again, if locality was an old one, that might have been handled

  • @homelessrobot
    @homelessrobot 10 หลายเดือนก่อน +3

    you guys talk about 'running' programs being some niche thing to haskell programmers... I have it on good authority that there is a subsect of hasklnauts that don't care about compilation at all beyond type checking. If it typechecks, some angel gets a bonus and stock options. Linting would probably get them 99% of the way to completion.

    • @teej_dv
      @teej_dv 10 หลายเดือนก่อน

      BIG IF TRUE

  • @BigfootPrinting
    @BigfootPrinting 10 หลายเดือนก่อน +15

    Prime went from turning me onto rust to turning me off pretty quick lol.

    • @natescode
      @natescode 10 หลายเดือนก่อน +6

      Apparently Prime used to not like Rust

    • @stysner4580
      @stysner4580 10 หลายเดือนก่อน +5

      Honestly I think that is because he does web stuff mostly. I/O bound issues mean you're kinda forced into using Tokio and the path of least resistance is always cloning or Arc'ing everything which become frustrating very quickly. Rust is very good if you plan beforehand. If you just want to get in and code away making stuff up as you go along it's rough for any medium complexity issue.

    • @maniacZesci
      @maniacZesci 10 หลายเดือนก่อน +1

      How about making up your own mind, instead of being influenced by some youtuber like that?

  • @throwaway3227
    @throwaway3227 10 หลายเดือนก่อน

    I know it's such a meme by now that it will never happen... but watching videos where you talk about clever stuff in OCaml makes me think you would really enjoy Haskell...

    • @Tomyb15
      @Tomyb15 10 หลายเดือนก่อน

      He would if he didn't have his head up his a** lmao
      One day maybe...

  • @ruanpingshan
    @ruanpingshan 10 หลายเดือนก่อน +2

    It's not just OCaml, even the new wannabe Python superset called Mojo is implementing Rust-like ownership. I don't know who in the Python community would actually want that.

  • @el_carbonara
    @el_carbonara 10 หลายเดือนก่อน +2

    jane st interns make me feel so worthless and insignificant

  • @mateuscanelhas5662
    @mateuscanelhas5662 10 หลายเดือนก่อน

    How does this mode work with relation to the type inference? You mention it is completely separate, so I'd assume that overloads are not a thing?
    One could imagine two definitions of map - A fast one that takes advantage of exclusiveness ( when given ) , and a default one. As I understand, the compiler would not be able to correctly dispatch to the best one?

    • @swannie1503
      @swannie1503 10 หลายเดือนก่อน

      If the compiler is able to do pattern matching when no argument is given, I’m sure it can compile into a similar kind of backtracking automata or decision tree as that case when handling the case when the type mode is specified or not. I could be wrong though. Interesting question and I hope somebody has a better answer!

  • @asdqwe4427
    @asdqwe4427 10 หลายเดือนก่อน

    Can I do grpc and graphql in ocaml?

  • @boreddad420
    @boreddad420 10 หลายเดือนก่อน +3

    CHROOT

  • @metaltyphoon
    @metaltyphoon 10 หลายเดือนก่อน +1

    “Colored structs”? There is no such thing as lifetimes ARE part of the type!

  • @sillymesilly
    @sillymesilly หลายเดือนก่อน

    WTF is oxidizing means in this context? Chemically combining with oxygen = oxidizing.

  • @alexandersemionov5790
    @alexandersemionov5790 10 หลายเดือนก่อน

    Lets say hi to RON here as well. Hiiiiiiiiiiiiii

  • @vasiliigulevich9202
    @vasiliigulevich9202 10 หลายเดือนก่อน +4

    OCaml is much older than Rust, it's funny, how people consider it borrowing.

    • @un9286
      @un9286 10 หลายเดือนก่อน +3

      if the concepts dont exist in Ocaml, then is borrowing

    • @Staphylokocke
      @Staphylokocke 10 หลายเดือนก่อน +1

      OCaml is older, but these `local` and `unique` modes are new extensions of it that afaik are not (and may never be) in the language. Rust on the other hand had ownership from the start.

  • @MarekFajkus
    @MarekFajkus 10 หลายเดือนก่อน

    These Haskell jokes are funny because we all know Haskell practically lives out of financial industry right? From Standard Chartered to the Cardano.

  • @timvw01
    @timvw01 10 หลายเดือนก่อน

    Its not faster so its unique point should be simplicity..

  • @worgenzwithm14z
    @worgenzwithm14z 10 หลายเดือนก่อน

    ST monad?

  • @natescode
    @natescode 10 หลายเดือนก่อน

    OCaml ❤

  • @BboyKeny
    @BboyKeny 10 หลายเดือนก่อน

    Hi Ron

  • @un9286
    @un9286 10 หลายเดือนก่อน +8

    PHP is faster

  • @k98killer
    @k98killer 10 หลายเดือนก่อน

    Regarding the opt-in mutability thing in Rust: you can't call it a variable if it isn't variable -- if everything is immutable, then nothing varies, so it ultimately isn't actually a variable. Perhaps "symbol" would be a better term, but then you'll get the attention of the Lispers.

  • @tonyhart2744
    @tonyhart2744 10 หลายเดือนก่อน

    why Ocaml always compare it to Rust ??? is that rust fork ?

    • @NC-nc3gs
      @NC-nc3gs 10 หลายเดือนก่อน

      Ocaml is kinda faster. Read somewhere it hovers around top 10. Its older than rust, but got many of features of newer languages. Imagine a language from 90s with package manager like rust. But don't know much beyond it though.

    • @mateuszschyboll2310
      @mateuszschyboll2310 10 หลายเดือนก่อน +4

      also first rust compiler was written in ocaml

    • @simonfarre4907
      @simonfarre4907 10 หลายเดือนก่อน +1

      ​@@NC-nc3gsOCaml is definitely, not remotely, even closely, faster than Rust or any of the C/C++ like languages when considering base line usage.
      There is plenty of simple/stupid benchmarking examples you can Google for and OCaml falls massively, several orders of magnitude in certain cases behind.
      Now, I know benchmarks like those should always be taken with a grain of salt, but it goes to show that no, OCaml can not be claimed to be faster than Rust.

    • @47bytes
      @47bytes 10 หลายเดือนก่อน

      @@simonfarre4907no one said it's as fast as rust but it is one of the fastest languages out there and I'd argue for the amount of abstraction ocaml has it is the fastest.

    • @simonfarre4907
      @simonfarre4907 10 หลายเดือนก่อน

      @@47bytes It is outperformed by c, c++, Rust, zig, d to name a few. I'm sure there are more.

  • @adambickford8720
    @adambickford8720 10 หลายเดือนก่อน

    I so want to dunk on prime for being borderline illiterate when reading out loud, except I do the same damn thing :(

  • @sarthik.poojary
    @sarthik.poojary 10 หลายเดือนก่อน +8

    Python is OP 🔥

    • @stevefan8283
      @stevefan8283 10 หลายเดือนก่อน +12

      Python is so trash it always have a global lock with it

    • @palgun.
      @palgun. 10 หลายเดือนก่อน +1

      No

    • @PranshuTheGamer
      @PranshuTheGamer 10 หลายเดือนก่อน

      ​@@stevefan8283gil is getting removed

    • @meanmole3212
      @meanmole3212 10 หลายเดือนก่อน

      Python is Obvious Pain (that makes you suffer in hell fire)

  • @FastRomanianGypsies
    @FastRomanianGypsies 10 หลายเดือนก่อน

    Everybody gangster until &'c