Writing an interpreter... in OCaml?!?

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024

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

  • @tini_
    @tini_ ปีที่แล้ว +150

    Tom is a genius!

    • @tapu_
      @tapu_ ปีที่แล้ว +20

      JDSL is the best language ever.

    • @teej_dv
      @teej_dv  ปีที่แล้ว +56

      oh no, the meme is spreading. it's broken containment from the degen army

    • @londospark7813
      @londospark7813 ปีที่แล้ว +9

      @@tapu_ Aren't you supposed to JDeez Nuts?

    • @leonvolq6179
      @leonvolq6179 ปีที่แล้ว +1

      Everyone in twitch programming knows the joke by now

    • @georgecop9538
      @georgecop9538 ปีที่แล้ว +1

      ​@@tapu_ until you add code comments, but yeah, genius.

  • @ameenkhieredeen6663
    @ameenkhieredeen6663 ปีที่แล้ว +123

    I love OCaml, would be great if you made an OCaml course or tutorials would definitely watch them.

    • @teej_dv
      @teej_dv  ปีที่แล้ว +30

      awesome! I'm considering how to do it. thanks for the feedback :)

    • @jsonkody
      @jsonkody ปีที่แล้ว +1

      Me too

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

      Here is a great playlist for learning ocaml.
      th-cam.com/play/PLre5AT9JnKShBOPeuiD9b-I4XROIJhkIU.html&si=WbnPg2gbb8qZnCuo

  • @JakobKenda
    @JakobKenda ปีที่แล้ว +48

    Yes, definitely do more of this.
    I don't think we need a full OCaml course, just learning alongside you explaining code is enough I think.

    • @teej_dv
      @teej_dv  ปีที่แล้ว +14

      cool :) we'll at least start with just "learn ocaml through seeing this code" i think

  • @bayrock1337
    @bayrock1337 ปีที่แล้ว +11

    Keep these coming, OCaml has been my language of choice recently and deserves attention.

  • @industry_std
    @industry_std ปีที่แล้ว +9

    When I discovered pattern matching with Elixir my mind was blown... and yet this looks even 'cuter'

  • @pharmajoe990
    @pharmajoe990 ปีที่แล้ว +7

    This is great, I’ve only ever heard of ocaml previously. Will have to have a play around, cheers

    • @teej_dv
      @teej_dv  ปีที่แล้ว

      sweet :) I hope you enjoy it! I'm having a lot of fun

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

    you're literally saving me and my bachelor thesis xD

  • @maleldil1
    @maleldil1 ปีที่แล้ว +1

    Please keep these coming! I've done the book in Go, so seeing a different way will be interesting. I can already see how much better pattern matching is compared to type switching on interfaces in the original.
    OCaml is a language that I used to be interested in (as a middle ground between Rust and Haskell), but I got put off by how inconsistent the community is. I can see it being useful for cases like this, where you likely don't need much outside of the core language.

  • @imhassane
    @imhassane ปีที่แล้ว +2

    Learnt it in my second year of university, couldn’t understand this language at the time but this code looks beautiful

  • @orbital1337
    @orbital1337 ปีที่แล้ว +2

    OCaml is pretty nice - especially for this kind of stuff! I've used it a bit in the past for automated reasoning & formal verification type work.

  • @rahuldevstech
    @rahuldevstech ปีที่แล้ว +2

    OCaml, my Caml!
    But, seriously: even more OCaml curious now. Thanks for sharing!

    • @teej_dv
      @teej_dv  ปีที่แล้ว +2

      well hopefully next few videos will convince you even more!

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

    10:13 oh I see it! I see the angstrom pattern matching there! Right? Interesting!

  • @rac116
    @rac116 ปีที่แล้ว +1

    Functional programming! 🎉

  • @pedrosaraiva1930
    @pedrosaraiva1930 ปีที่แล้ว +1

    15 years ago at my university class we were assigned to build a interpreter in OCaml and Prolog

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

      My own Master's final programming project was to implement a compiler whose
      (i) source language was Prolog extended with certain features which come in handy when you are writing compilers in Prolog
      (ii) object language was standard Prolog
      (iii) implementation language was... Prolog, of course.

  • @tyrox9
    @tyrox9 ปีที่แล้ว +1

    Really liked the video, what i would like to see is how to use dune/run tests or an explanation on how to use modules. I tried to read the documentation and i could not figure this things out.

  • @tavin136
    @tavin136 ปีที่แล้ว +2

    I'll [[likely]] save this for later.

  • @Honken
    @Honken ปีที่แล้ว +2

    Subscribing for OCaml content! One of the nicest programming languages in existence.

  • @rickdg
    @rickdg ปีที่แล้ว

    Nice to see your first ocaml my caml video. If you can find a way to have your green screen a little further back, you can probably prevent the green reflection that its casting on your head.

  • @charstringetje
    @charstringetje ปีที่แล้ว +1

    Any curried ML language is nice, and Rok too (even though it doesn't curry functions by default). With OCaml I just had to get used to the French ordering of product types: `int list` instead of `List Int`. French acronyms can be confusing in the same way.

  • @fredericchopin255
    @fredericchopin255 ปีที่แล้ว +1

    Wow! We do ocaml in france and i had a project for writing mini compiler of java using ocaml

  • @draakisback
    @draakisback ปีที่แล้ว

    I love Ocaml, glad you decided to make a video on it. I know you're pretty hot on the language also but obviously it's not as popular as say rust for example. I'm looking forward to the opam Windows release since I do most of my development on Windows. Fortunately in the meantime we have DKML which is pretty fantastic.

  • @TerryDellino
    @TerryDellino ปีที่แล้ว

    I’m enjoying these Ocaml videos! I have always loved functional programming languages, but never got into Ocaml. I need to give it another look. Pattern matching makes code really easy to reason about IMO

  • @tofuman9526
    @tofuman9526 ปีที่แล้ว

    Yes yes, it’s fun to watch OCaml lang used to make something interesting like this. Would love to see an API development or something too

  • @AlleBalle54
    @AlleBalle54 ปีที่แล้ว

    great video, the mattern matching looks very intressting and think I would've loved it for a use case I had the other day

  • @TayTayChan
    @TayTayChan ปีที่แล้ว

    Long overdue video, Teej! I knew you were doing some OCaml and got curious, but try as I might I'm not made for watching live streams.
    Interesting implementation, would love to see more. I did some ML back in the day, so it's not completely alien.

  • @The45DegreesProject
    @The45DegreesProject ปีที่แล้ว +1

    This is cool. First time I see OCaml and sort of get what is going on :D

    • @The45DegreesProject
      @The45DegreesProject ปีที่แล้ว

      I’d love to see more on OCamls type system and how modules/functors work

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

    You did an amazing video, the idea is interesting I’m doing the same but with rust to learn it 🌚 continue the great work plz

  • @StopBuggingMeGoogleIHateYou
    @StopBuggingMeGoogleIHateYou ปีที่แล้ว +3

    I want to encourage you to keep making videos like this because OCaml is a brilliant and beautiful language for programming language theory. That said, the clickbait title was a bit jarring. "Writing an interpreter ... in OCaml?!?" This is exactly what OCaml excels at! There's nothing surprising about writing interpreters in OCaml!

    • @teej_dv
      @teej_dv  ปีที่แล้ว +8

      but... do most people know that? :)

    • @jp2kk2
      @jp2kk2 ปีที่แล้ว

      @@teej_dv I sure didn't!

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

    Would love to see more OCaml videos!

  • @nemartin1
    @nemartin1 ปีที่แล้ว

    Subscribed just for the future OCaml videos.

  • @arisweedler4703
    @arisweedler4703 ปีที่แล้ว

    this is awesome. Would love to see more of this

  • @WillEhrendreich
    @WillEhrendreich ปีที่แล้ว +1

    Great stuff, love it.

  • @user-hy4mo1xu5p
    @user-hy4mo1xu5p ปีที่แล้ว +4

    keep it up with ocaml videos 👍

    • @teej_dv
      @teej_dv  ปีที่แล้ว

      will do!

  • @pauloffborba
    @pauloffborba ปีที่แล้ว

    This remember the Elixir code 👏🏻👏🏻 Great video!

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

    Ah I finally found your channel
    At last the algorithm is working as it should

  • @Danielo515
    @Danielo515 ปีที่แล้ว

    By the way, if you want to keep people hooked and understanding the syntax easier, you could consider using reason syntax. It is the same, but with a more C-style looking

  • @goosechaser
    @goosechaser ปีที่แล้ว

    Bought this book months ago and was unironically going to write it in OCaml too! Lmao. Learned OCaml for functional class in school

  • @xtsxo9872
    @xtsxo9872 ปีที่แล้ว

    great video! really interested to see more ocaml

  • @AXYGaming
    @AXYGaming ปีที่แล้ว

    Ocaml has built in support for lexing and parsing with .mll and .mly extensions with ocamllex and ocamlyacc respectivly

  • @diegolikescode
    @diegolikescode ปีที่แล้ว

    waiting for the playlist, babie!

  • @un9286
    @un9286 ปีที่แล้ว +1

    I would actually like some tutorial in how to make the Ocaml lsp work in nvim

  • @kylestubblefield3404
    @kylestubblefield3404 ปีที่แล้ว

    We need all the OCamls!

  • @viktorhabchak470
    @viktorhabchak470 ปีที่แล้ว

    More OCaml!

  • @Blure
    @Blure ปีที่แล้ว +1

    Thanks for the video TJ. Could you please share your ocaml setup for neovim? Mine is not showing type hints like yours. Thanks :)

  • @mustafazakiassagaf1757
    @mustafazakiassagaf1757 ปีที่แล้ว

    i love this video. Maybe having a little bit live coding explaining how to solve something in ocaml would be nice

    • @teej_dv
      @teej_dv  ปีที่แล้ว +1

      come watch on twitch :) twitch.tv/teej_dv

    • @mustafazakiassagaf1757
      @mustafazakiassagaf1757 ปีที่แล้ว

      ​@@teej_dvahh I did not know that you also stream it. gonna watch the vod

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

    Functional languages seem great for writing parsers

  • @RoccoGhielmini
    @RoccoGhielmini ปีที่แล้ว

    Love it love it!! Keep going

  • @Tala2n
    @Tala2n ปีที่แล้ว

    Ocamllex is included with Ocaml package. So I use it for the lexer. I refuse to use ocamlyacc, that adds dependency and Ocaml is sufficiently cool to implement a parser.

  • @nickskywalker2568
    @nickskywalker2568 ปีที่แล้ว +1

    thanks for the ocaml love

    • @teej_dv
      @teej_dv  ปีที่แล้ว +1

      my pleasure, more coming soon!

    • @nickskywalker2568
      @nickskywalker2568 ปีที่แล้ว

      @@teej_dv nice! Let's get ocaml some momentum in the industry!

  • @shivisuper91
    @shivisuper91 ปีที่แล้ว +1

    More functional programming please! Also, did you create your own plugin to show type hints for each function or there's an existing plugin for it?

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

    And now the scary part: the name is originally an acronym for
    Objective (as in OO)
    Categorical (as in Category theory in math - yes, monads & c.)
    Abstract (as in device independent meaning for its programs)
    Machine (as in reduction rules which implement that meaning)
    Language (as in a notation for the C and A above).
    It's really a clever decoy which tempts you from the bountiful fruits of Real Programming into the arid wasteland of Computer Science - with the tacit goal to make you unemployable...

  • @RoryIsNotACabbage
    @RoryIsNotACabbage ปีที่แล้ว +2

    Hey teej is back 😀

    • @teej_dv
      @teej_dv  ปีที่แล้ว +1

      haha finally :) hoping to get back into making some new videos more regularly

    • @RoryIsNotACabbage
      @RoryIsNotACabbage ปีที่แล้ว

      @TJ DeVries I look forward to it. ngl was sad there was no 0.9 launch party

  • @jackevansevo
    @jackevansevo ปีที่แล้ว +3

    This code looks so elegant compared to the Go implementation.

    • @teej_dv
      @teej_dv  ปีที่แล้ว +1

      LETS GOOOOOO

  • @ersstuff
    @ersstuff ปีที่แล้ว +2

    The C A M L, with an O at the front
    It’s not imperative scaring ya, and we ain’t tryna stunt
    Just tryna process every single type to keep it in check
    And having higher-order fun with it is just a side effect
    (c) rangersbeats

    • @teej_dv
      @teej_dv  ปีที่แล้ว +1

      very nice lyrics

  • @sgwong513
    @sgwong513 ปีที่แล้ว

    never lean OCaml before, although you try to explain it but still couldn't get how it works(I also haven't read the book for how it implement the lexer). Might see the code offline again. but it seems fresh and interesting to look at functional program with OCaml. had been doing imperative programming for so long time.

  • @marcusrehn6915
    @marcusrehn6915 ปีที่แล้ว

    Seems really cool, would love to see other examples!
    A bit curious about the performance, but mostly really curious about the ecosystem. Is there a package manager that people actually use and are there implementations for graphl and grpc as well as the most common databases?

  • @ercpereda
    @ercpereda ปีที่แล้ว +2

    That was awesome! Can you share the resources do you use to learn OCaml?

    • @teej_dv
      @teej_dv  ปีที่แล้ว +3

      Mostly:
      1. Reading the official docs from ocaml.org
      2. Starting to build things :)
      also, asking friends in discord / twitch / etc.

  • @hyto
    @hyto ปีที่แล้ว

    Awesome video, keep them coming.

    • @teej_dv
      @teej_dv  ปีที่แล้ว

      Will do :)

  • @talhaakram
    @talhaakram ปีที่แล้ว +1

    love this.

    • @teej_dv
      @teej_dv  ปีที่แล้ว

      love this comment :)

  • @coptan99
    @coptan99 ปีที่แล้ว +1

    Which theme do you use?

  • @kylegaijin
    @kylegaijin ปีที่แล้ว +1

    I'm beginning to love Ocaml. It's the language that would be born if Rust and Go had a baby. By the way you went through the code really fast, so it was difficult to grasp a lot of what you were saying. Do you have this code posted on github? I looked, but I didn't find it.

  • @dacam29
    @dacam29 ปีที่แล้ว

    I studied OCaml at university in 2007.... crazy

  • @jakeshoemaker1483
    @jakeshoemaker1483 ปีที่แล้ว

    This was really cool.

  • @--------------------.
    @--------------------. ปีที่แล้ว

    OCaml seems really nice! I wish i started my fp journey with it instead of Haskell!

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

      I did it the other way around: First Standard ML and Caml - because it was and still is the only ML with a pulse - but then turning to Haskell because some features of Caml were not quite orthogonal,
      Whenever you add later a totally different programming or data model into an existing language, you are bound to see the stitches which keep that Frankenstein's monster together. As proof, compare
      (i) the Java generics, which added parametric polymorphism into what had been so far a purely object-oriented language with ad hoc and subtype polymorphism
      (ii) the "O" which added objects into Caml which had been so far purely parametrically polymorphic
      (iii) Haskell which developed instead the fresh idea of classifying types and not values. In OO terms, they did introduce ad hoc polymorphism, but for interfaces only. Values stayed intact, and hence parametric polymorphism continue working as before.

  • @rohithsuresh1877
    @rohithsuresh1877 ปีที่แล้ว

    Banger of a video teej!! How do you have an end of line marked in neovim(the return symbol at the end of each line), is it some plugin?

    • @Mankepanke
      @Mankepanke ปีที่แล้ว

      Native. See :help list and listchars

  • @mumk
    @mumk ปีที่แล้ว

    The syntax of OCaml and F# bears a striking resemblance

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

      ...because F# began essentially as "Microsoft OCaml"...

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

      Java is to C# what OCaml is to F#. Same with Pascal and AL

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

    I love neovim!! ❤

  • @Danielo515
    @Danielo515 ปีที่แล้ว

    You’re officially hooked in Ocaml, nuahahaha

  • @thomasfrans1185
    @thomasfrans1185 ปีที่แล้ว

    This was very interesting!

    • @teej_dv
      @teej_dv  ปีที่แล้ว

      Thanks!! :)

  • @felgenh399
    @felgenh399 ปีที่แล้ว

    keep it comin'

  • @piotrjaga6929
    @piotrjaga6929 ปีที่แล้ว

    do you mean like PiterDeVries in diune?

  • @matthewrossee
    @matthewrossee ปีที่แล้ว +1

    Great video, ocaml seems pretty cool. I have kinda mixed feelings about immutability though. I love the idea behind pure functions, but how do the performance and memory consumption compare to mutable solutions? It seems like the lexer is allocated for every token. Does ocaml perform some kind of optimization behind the scenes?

    • @teej_dv
      @teej_dv  ปีที่แล้ว +5

      ocaml's compiler and garbage collector are optimized for lots of small, immutable allocations! In some cases, making many small objects (that are all declared mutable) is actually faster than creating mutable ones (because the compiler can make more optimizations).
      It's not like trying to write immutable code in javascript.

    • @teej_dv
      @teej_dv  ปีที่แล้ว +2

      but that's a great question and concern!

    • @worgenzwithm14z
      @worgenzwithm14z ปีที่แล้ว +2

      Persistent data structures can be used to minimize copying!

    • @anderdrache8504
      @anderdrache8504 ปีที่แล้ว +2

      In general, immutable functional languages are mostly slower than something like C or Rust but they are often faster than mutable and garbage-collected languages. Immutability provides a bunch more possibility for optimization!

    • @matthewrossee
      @matthewrossee ปีที่แล้ว +1

      @@anderdrache8504 Do you know some good articles or something like that about such optimizations? I'm really interested how it works under the hood.

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

    I’m curious to know why you chose OCaml specifically out of all the FP langs.
    Like why not Haskell, for example?

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

      Apart from being able to use monadic parsing expressions - which is admittedly a _huge_ win! - laziness does not really buy you much in compiler writing. In contrast, say, Prolog-style logical variables with unification make backpatching semi-generated code much simpler.

  • @NathanHedglin
    @NathanHedglin ปีที่แล้ว

    Ocaml os amazing for interpreters

  • @dezorted2834
    @dezorted2834 ปีที่แล้ว

    thevimteejen came back!

  • @timjames4306
    @timjames4306 ปีที่แล้ว +1

    Require a NeoVim installation and setup guide Video for Windows User also.🙌✌

  • @vaishnavmhetre9061
    @vaishnavmhetre9061 ปีที่แล้ว

    Tom spelled Immuntable in comments ❤️

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

    Is Ocaml Rust daddy! If so, whats the big deal?

  • @MENTOKz
    @MENTOKz ปีที่แล้ว

    does ocaml have easy concurrency like in golang? but yeah i like the video

    • @noname78520
      @noname78520 ปีที่แล้ว

      they just added multicore support in the last version 5.0

  • @Vanna1321
    @Vanna1321 ปีที่แล้ว +1

    chad

    • @teej_dv
      @teej_dv  ปีที่แล้ว

      actually, the name's teej ;)

  • @ebukaezike9308
    @ebukaezike9308 ปีที่แล้ว

    What Font is this ?

  • @marcobuess
    @marcobuess ปีที่แล้ว

    seeing ocaml makes me miss f#. 😢

  • @desuburinga
    @desuburinga ปีที่แล้ว

    Ocaml my caml with FEM maybe???

    • @teej_dv
      @teej_dv  ปีที่แล้ว +1

      Maybe if they get tweeted at a bunch about it :)

  • @slowjocrow6451
    @slowjocrow6451 ปีที่แล้ว

    Hey teej, can you explain c# yield to a noob? I'm really struggling to understand

    • @teej_dv
      @teej_dv  ปีที่แล้ว +2

      c# yield is like "return" but it keeps the state of the function call, so you can resume it later ( I think)

    • @_idiot
      @_idiot ปีที่แล้ว

      could google and read 100 explanations instead of wait for him to answer a youtube comment

    • @slowjocrow6451
      @slowjocrow6451 ปีที่แล้ว

      @@teej_dv Thank you. I saw it in a video with you and Prime recently. You two look like you have so much fun streaming together. Thanks for being so inspiring ❤️

  • @maman14141414
    @maman14141414 ปีที่แล้ว

    i know nothing about ocamel but i have for sure seen you using your superior typing speed to make an appearance on AsmonGold stream

    • @teej_dv
      @teej_dv  ปีที่แล้ว +2

      Whilst the older games certainly had a lot of multiplayer, they were absolutely viable single player games. Do you feel this element will be lost with the ever increasing push towards seasons and battle passes in diablo 4?

    • @maman14141414
      @maman14141414 ปีที่แล้ว

      @@teej_dv now a days everything has a battle passe,and most of the time it doesn't serve any purpose beside making money, you should take a look at the video about abusive monetisation strategies that asmongold reacted to very informative

  • @twenty-fifth420
    @twenty-fifth420 ปีที่แล้ว

    Looks like my comment got flagged somehow, I just think OCaml looks pretty is the primary takeaway I got from here 😂.
    I want to make it work with Godot somehow. ⭐️

    • @teej_dv
      @teej_dv  ปีที่แล้ว

      haha, i'm sure it's possible.... given enough time haha

  • @JohnWasinger
    @JohnWasinger ปีที่แล้ว

    Is Ocaml easier than writing with flex and yacc?

    • @teej_dv
      @teej_dv  ปีที่แล้ว +1

      Hmm... I think flex/yacc can often be "easier"... until they're not. Once you want to try and do something non-standard, you'll have a hard time. The point of the series isn't to pick the easiest way to write an interpreter, but instead to understand what is happening under the hood.

    • @havocindustries3078
      @havocindustries3078 ปีที่แล้ว +2

      Flex and yacc are code generators. They open a can of worms beyond imagination. Code generation is pure evil. Stay away from those and use a language that allows you to express ideas in a concise way. Haskell, OCaml, F#, Scala, Rust are good examples.

    • @anderdrache8504
      @anderdrache8504 ปีที่แล้ว

      Lexers and parsers are in my opinion not hard enough problems to justify parser generators. Of course use what you like but parsing is so simple that you can just do it yourself and be more flexible!

  • @manzutu
    @manzutu ปีที่แล้ว

    Can you do an Ocaml course?