 Hello everyone. Welcome to the session OCaml platform in 2022. We are very glad to have Sudha join us today. So without further delay, Sudha, over to you. So, welcome everyone. Thanks for joining my session on OCaml platform in 2022. Just to give you an introduction of the cycle. I'm a software engineer at Daredis. I joined the OCaml team two years ago at IIT Madras, and since then I've moved to Daredis to do the same task. So, in this session today, I hope to give you all a quick tour of the various components of the OCaml platform, which will hopefully enhance your developer experience of using OCaml. And before I begin, I would like to thank all the people who have been involved in such a remarkable work of making the OCaml platform in a way that's very pleasant to use. So, thanks to all the OCaml platform developers and maintenance for the way that's nice. So, just to give a very quick introduction about OCaml to people who might not be familiar with OCaml at all. OCaml is a functional programming language in its core. It is ML summary language, which started with standard ML, and OCaml is a spin-off of it with interactive and object-oriented features, which has been quite useful for a lot of work, to be honest. But in its core, it's still a functional programming language with a lot of purely functional features, and that are the most useful features in OCaml. So, it has a strong static typing. How is it useful? So, when we say strong static typing, it means the compiler is available, sorry, the compiler is aware of your type. So, what that means is the compiler will not allow you to compile unless your typing information is right. And as the saying goes in the FD community, if your program compiles, it works. So, OCaml has strong type, and it also doesn't mandate you to write the type yourself because it uses type instruments to insert whatever type your functions have, which gives you very strong typing features to make your experience of writing OCaml programs easier. It also has algebraic data types, which make representing any data subject very easy. You will see some examples in the subsequent slides of how ADTs are represented in OCaml. It also has pattern matching, quite similar to Haslip's pattern matching, except for the syntax. And pattern matching makes sure that your code is exhaustive. It means that there won't be any oversights in missing out some of the items in what the function is going to cover. So, ADTs and pattern matching are one of the very main features of OCaml in my opinion. And contrary to popular perception that FD languages are not featured for the systems programming, OCaml has very nice features to allow systems programming. It has very good unique findings, and it also helps that OCaml has DC, which is badly tested and it is very performance. And at the same time, it supports the C-SFI, which has a very strong C-SFI, which makes writing C bindings very easy. So, OCaml has been used for a lot of systems programming. Again, contrary to the popular perception that FD languages are not used for systems programming. And like I mentioned just now, OCaml comes with the garbage collector. So, OCaml uses minor and major collectors. The minor collector is quite fast. So, there isn't much DC overhead from this. We are allocating a lot. So, the DC helps us not having to do the memory management by the programming. And OCaml is going to have multi-core and effect handlers basement. We are really looking forward to the release of OCaml 5, which will bring in multi-core, which has been one of the most anticipated features in OCaml. The work is done, and we can expect the release sometime possibly in the next quarter, maybe during the end of June or so. I don't take my words for it, but that is the current timeline. And I currently need a team that is helping the community move with OCaml 5. And we hope to have more people start with me at OCaml once we release OCaml 5. And this task is making the developer experience more pleasant to people when they start using OCaml. And as much for people who have been using OCaml for a while now, and they would like to try out the new features that have been added to the OCaml platform. So, to get OCaml, it's quite straightforward. All we need is the OCam package manager. And to install OCam package manager, you only need this one line. This batch script is going to install OCaml for you on Linux and Mac. So, procedure is slightly different in Windows. If you are interested in using OCaml on Windows, I would recommend using WSN. It is also possible to use it naturally on Windows, but the procedure is slightly different. And due to the time constraints, I am not able to cover the Windows part. But I would definitely encourage you to look at the nature of Windows support if you are interested in using OCaml on Windows. So, coming back to OCaml, one line is going to install the right version of OCaml first on whatever system they are using on Linux or Mac. And right after we install this, we just have to run OCaml in it which is going to initialize the configuration for us. So, after you init the OCaml, it's going to install the default switch. Default switch is usually the latest release compiler, which is 4.13 right now. But OCaml also allows us to actually install more than one compiler version at the same time which makes it easier to test different versions of packages. So, for example, some packages should support only certain versions of the compiler and will not support newer versions or older versions. So, when you have multiple compilers at the same time, it makes it easier for us to actually use it on different test cases. So, just to show how this works, I can show the different switches that I have right now. These are all the switches I have right now. I have so many, I know. Usually, we don't need these any switches. I had been hacking on the compiler because I have these many switches. So, yes, it's just running this one-line fast-crypto into the OCaml and we are on to a start. Before I go further, I would like to give you all a big picture of what the different components of the OCaml platform are. I mean, don't worry if a lot of it is not making sense right now. Hopefully, we'll connect the dots as we go along. So, to talk about the different stages of the OCaml platform, as you can see, there are many different components that work together and the community has been working very hard on all of these packages. The first stage is integrating some of the packages. These are quite new packages, these are quite new packages, but they are very useful. So, folks are working very hard on developing them and making them stable. The first two items in the incubate stage are the OROC and MDX. Both of these are the documentation tools. OROC allows us to write documentation within the code for the files itself, so that you don't have to write documentation separately. MDX allows us to write for the within mark zone files and also execute. We'll be seeing them in detail later. I'm just giving a quick introduction of all this right now. LSD server is the language server protocol. This can be used with your favorite executor to make it work like an IDE. There are many interesting features in the LSD server. I'll be showing some of them in the subsequent space. OCaml formats automatically formats our OCaml code to comply to the accepted standard. It's very useful, especially when there are multiple people working on the same code base to maintain uniformity in the code base. Dune release allows us to release libraries. It's supposed to work with Dune, the package manager, and the libraries that are hosted on github. Opam is the package manager that we talked about earlier. Dune is the build system that's widely used by OCaml developers. Ptx is a useful set of libraries to write Ptx extensions for your OCaml platforms. Utop is Reptile, which has more features than the repels that ship to the compiler. Opam Publish allows us to publish the new versions of libraries on Opam repository. Opam repository is the central source of all the Opam packages. That's where we install the released Opam packages from. Merlin is supposed to work with the LSD server on providing nice, tidy features like auto-complete the plain sites on the file and so on. We'll be seeing it in the next part of the presentation. The tools that fall under sustain have been in the community for a while and I would say they are legacy tools. They're not actively developed anymore and there are no new features being added to the tools under sustain. We do have many packages and libraries that use these tools. They are in sustain mode for a while until they're deprecated. They would still work with the current features but they wouldn't add any new features. OCP indent is an indentation tool. Now that we have OCP formats, we don't need a separate tool for the indentation. It's in sustain mode. OCP builds and OCP signs are the predate doon. The doon has essentially overrides the OCP build and OCP sign. Projects that use OCP build and OCP sign would still work but they are impregnated to doon to make it use more latest features of OCP. These libraries that fall under deprecates are deprecated and they are in the path of being removed from the existing projects that use them. OYAS is in Germany before the libraries that fall under deprecates. OYAS is a bridge manager and again it's a doon overrides OYAS. So it's not needed anymore. Alright, so now that we had a very quick overview of what's the different components of the OCP platform are, I'll move on to giving you all a very quick demo on how these different things work. We will not cover all of this but we will be covering the most useful part used in the day-to-day work of OCP development. Alright, the first thing is the repel. So OCaml top level is the repel that shifts the OCaml compiler. So when you just run OCaml on your terminal, it's going to start the repel for you. It also mentions current version that you are on. If you see that you are on the wrong version, all you have to do is you have to switch to the right compiler version that you want to select. And you have to evaluate the OCaml environment to make sure that you are using the right OCaml version. That's going to give us the repel. And all the instructions to the repel are ended with two semicolons to say that's done with what I want to run. This is a nice way to play around with, especially when you're starting to learn OCaml and also when you're developing something new. It makes it the same with what you're writing with. So this is the OCaml top level that shifts the compiler. We also have new top like I mentioned earlier. OCaml is built on top of the OCaml compiler top level. But it has more added features that make it easier for us to use the repel. For instance, OCaml supports code completion with the tabs. So if you see the code that's running right now, it's using the autocomplete on the list and it's all that's going there. It also displays the type of the function. If you are not sure what the type of function is, just run it on utop. And utop is going to display the type of the function for you, which makes the using the API quite lucrative. And it also has the syntax highlighting and maybe getting yourself quite nice on utop when you compare it with the OCaml top level. So it's recommended for people to use utop if they want to use repel. For example, if they want to execute the previous block, we just prep up like we do on terminal. Unfortunately, that doesn't work on the OCaml top level. The utop has worked around and it's quite nice. I would highly recommend playing with utop to secure using OCaml for the first time. Yeah, and Dune is the build manager. So Dune was initially developed at the GnStreet internally and later we had released it. They had made it open first and now Dune is the default build manager that's used in new OCaml projects. Dune makes working with OCaml projects quite nice. So you can initialize the project, the new project with Dune and initializing the project as you can see in the terminal. Initializing has two modes, project mode and library mode. So once you initialize it with the project mode that couldn't have any executables, when you initialize it with the library mode, it will create your tests and all of the other libraries, the basic ones for you. So that gives you the skeleton of how your project is going to look like and we can go from there. Dune, yeah, of course Dune builds all the libraries and executables. Dune also allows us to run tests to Dune, run test command. And we can also execute the executables to Dune. So this is the complete package in how you can build your OCaml project. Dune also has more features. Dune is in its construction composites. What do we mean by composites here? Let's say we have any different projects and they use Dune. It's quite simple to combine all of them. Let's say we put all of them into one directory and have a top-level Dune project there. Then Dune will certainly be able to recognize all of the projects and compile and run all of them. So that now becomes a single Dune project. So combining and splitting libraries is quite simple with Dune if all of them are in use Dune. Dune also supports cross compilation. So Dune supports having separate targets for Linux, Mac and Windows. Usually it's not mandatory to configure them unless you are using some OS-specific features that are present in the project. So Dune also supports OCaml. Of course it supports OCaml and it makes the workflow of merging with OCaml quite easy. Dune supports FFI also, especially the CSFI is quite widely used in the OCaml community. Having feedback makes it easier to communicate with other projects and some of the low-level stuff. So Dune has sufficient for the specifying FFI within the entire system. There's no need to compile them separately. Dune supports pdx as well. pdx, for instance, are quite useful for many of the OCaml projects. And Dune does have provisions to specify what pdx we are using in the project. And Dune also supports JavaScript, which is a case of OCaml. There's a OCaml that's used to write web applications with OCaml. So yeah, Dune as a Dune is quite versatile. So that's just about the Dune. Now going on to the IDE experience. So there's usually this notion of OCaml lessons have an IDE. So OCaml LSD server comes quite close to it. It's possible to transform your favorite text editor to an IDE. So the IDE can be made with Emacs, Wim and Vfood that I know of. I would personally be using Vfood because that's what I used in my day-to-day work. But it's possible with Emacs and Wim as well. For Emacs, you need the LSD mode of Emacs and OCaml LSD server. For Wim, you would need Wim LSD and OCaml LSD server. And for Vfood, you would need the Vfood OCaml. So this button that you see here is going to let us generate the ML file from the ML file. And we don't have to do it manually. Which is very nice. ML files are usually used to write API documentation. So all you need to do is just write the documentation and not go over this part again. Which is quite useful in my experience. So the next one is hovering for types. So when you see this program and when you just hover over some function or some part of a function or some variable, it's going to show us the type. Which is very useful especially in largest functions to look at parts and see what the sub part of the function is returning for us. And this has also been very useful as and when you write new OCaml programs or even when you are looking at old code business. So this is another part of the IDE experience. The other part is autocomplete. So Merlin has this nice autocomplete feature. You can see in this code the autocomplete feature is being displayed. It's quite nice. It's going to show us the modules and the functions of the modules. And it also displays the types of the functions for us. So it makes writing new functions quite intuitive because you see the type here itself instead of us having to look at the API docs going back and forth between the API docs and between the source files. So this is the other part of the IDE experience. So the next part is formatting code. So like I mentioned earlier, this OCaml format makes the formatting uniform with an agreed upon standard. So as you see here, this is the old formatting that I had used while writing the code without having any standards in mind, coding standards in mind. And once you run it with OCaml format, it's going to give us this nice reordering of the code. This is a quite nice to look at. And it also makes the entire code base uniform for us. So let's say we have multiple people working on a single package or a single code base using OCaml format is going to make all of it uniform. So it's quite useful for both large projects and for small projects. So all we need to do for running OCaml format is it's supported by Doon. So Doon build, just Doon build is going to build the project for us. Doon build at FMP is going to invoke OCaml format. And that's the formatted file is going to be present in the Doons build folder. If you want to use that in your code, we need to run this Doon promote, which is going to copy the formatted code from the Doons folder to our original source file. So it's quite simple. And I would recommend running this OCaml format every time we write something so that it just stays the entire code base stays uniform in the styling. Yes. And okay, coming to the part about documentation. We have two tools that are quite actively being developed right now. So the first one is MDX. MDX, yeah, as you can see from the name, it supports markdown. And it also supports OCaml documentation tool, ODOX documentation format. So this MDX is MDX allows us to write code within markdown file. So let's say we have a readme file, which is going to demonstrate some features and we have some code there. MDX allows us to actually run the code that's present in the markdown files. So this actually helps us in keeping the documentation up to date. So we don't have any stale parts in the documentation. It's very annoying when you have documentation and have code snippets in documentation, but when you actually try to run them, they don't work. So MDX helps us in eliminating that. So MDX was born out of this while writing this book, Real World OCaml. I would highly recommend reading that book if you want to learn OCaml. So MDX was written during writing the book Real World OCaml and it was very useful for writing book. And it's also being used in many other projects right now. So these are just the config things that we need to specify in these files. And Doon Run Test would by default run all the markdown files for any code snippets. And the next one is ODoc. So ODoc is the documentation tool and it generates HTML pages and man pages and Latin documents from the documentation that's embedded in the source itself. So when we have comments of this form, so OCaml comments are usually, they don't need two asterisks here. Just one asterisk is sufficient for the comment. But for ODoc comments, we need this specific format for it to be passed as documentation comment. So it just takes out whatever comments that are present in the source files and it displays it as a HTML file. So this is ODoc generated documentation of one of the modules. So it is quite nice to actually have the documentation embedded in the code base itself rather than having to write documentation separately. So ODoc has a separate format called MLD which we can use for writing long form documentation. So this is just the API docs that you see here. The MLD files allow us to write tutorials and some of the long form documentations of that sort. And they are also clubbed together with the API docs. So you have all the documentation together at one place and you don't have to redirect people to different places for looking at the documentation. ODoc is being actively developed and new features are being added. So I'm quite excited to see how that evolves. So Dune Release is a tool to actually just add the release of your new libraries or new versions of your existing libraries. So all we need to do is create a tag. Dune Release tag is going to parse the tag from the changes file for us and Dune Release would create the release which can then be uploaded to GitHub. Yes, and the release packages should be published in the OPAM repository. So OPAM repository is the single source of truth for OPAM packages. So all the released OPAM packages are present in the OPAM repository. So it's the central source of all OPAM libraries. So this is the default OPAM repository and any and every release is going to go there. OPAM repository also allows us to have custom OPAM repositories. So if you don't want your library to be released in the OPAM repository and you just want to test it out, we can create our own OPAM repository which is going to host the packages for us and set that as one of the sources in OPAM and we can then install packages from the custom repository. So it will not be exposed to people who don't have access to the custom repository. So to release libraries to OPAM repository, we have this tool called OPAM Publish which publishes packages for us. So after all the tagging and release on GitHub is done all we need to do is call this OPAM publish within the package directory and it will take us through some items like it will ask you to enter your GitHub token and it will show us the patch right before it's submitted to OPAM publish. So this is one of the sample PR that was generated with OPAM publish. You can see that being mentioned here and to release the library we need to add the dot OPAM file that's present in the library to the PR and it's going to create a patch for us and once that patch gets merged the library is released. So it's quite simple to create a new package, new versions of packages and even release new libraries. Yes, so before I finish we are hiring for many positions at Canada's. So if you are interested in working with the camera Lord just want to check out what it is. Feel free to ping me. Yeah, and that is all about the presentation. I would be happy to answer any questions if there are any. Thanks to that. You really maintained your calm during the technical over there. So really appreciate your composer in that one. I am sorry about the glitch. No worries at all. We handle it like live demos and recovering this live it's great. So glad we were able to do that. So there is one question that let's get to first. Okay. So Rick is asking what is the difference between do release and publish. Okay, that's a good question. So do release is just going to pack the package for us and put it on GitHub. Under the tag the version releases open publish actually adds it to the open repository and that is when people will be able to install the package. So the first stage is to release and the next stage is open publish. If it makes sense. But Rick, I hope that makes sense.