[00:00.000 --> 00:10.740] Okay, so here is a quick overview of Haskell today. I am Julien DeRos, I am an assistant [00:10.740 --> 00:16.020] professor in computer science, and I use Haskell since 2015 initially for teaching [00:16.020 --> 00:23.480] functional programming. So since the beginning of the language, Haskell has many tools that [00:23.480 --> 00:29.400] have been created for developing in Haskell, and today most of the Haskell developers use [00:29.400 --> 00:34.920] GHC compiler for building Haskell projects. We have a nice tool such as a cabal or stack. [00:34.920 --> 00:43.080] Haskell is now quite well integrated in editors such as Visual Studio Code, Veeam or Emacs, [00:43.080 --> 00:52.200] thanks to LSP implementations such as HLS, and all these tools can be installed using some tools [00:52.200 --> 01:00.320] like GHC or Nix. In this talk, I will focus on cabal with VS Code and the Haskell plugin. [01:00.320 --> 01:07.320] First, we have some online tools such as a package, which is a package archive, [01:07.320 --> 01:13.360] so you can go to the website and search for packages. There is for example some [01:13.360 --> 01:22.360] libraries for doing whatever you want. These libraries, you can access their documentation so [01:22.360 --> 01:28.680] you can see what to do with this library and how to use it, and you also have access to their [01:28.680 --> 01:36.120] source code, with nice colors and code navigation, which is quite useful. We also have [01:36.120 --> 01:43.160] Google, which is Haskell Google, so it's a search engine, and you can type the name of a function, [01:43.160 --> 01:49.520] and Google will give you a link to the documentation of that function in the package. If you don't [01:49.520 --> 01:55.480] know the name of the function, you can also type, write the type of the function, and Google [01:55.480 --> 02:01.400] try to find a function that matches that type, so you can see its documentation on the package, [02:01.400 --> 02:09.280] and you can see if it's the function you are looking for. To work on a Haskell project, [02:09.280 --> 02:18.120] you can use cabal, which is a tool for building and packaging projects. To use cabal, we have [02:18.120 --> 02:25.200] to write a cabal file, which is a configuration file, where you can specify some information [02:25.200 --> 02:30.920] about your project, and also define the target you want to build in your project. For example, [02:30.920 --> 02:36.040] if you have a library or executables, you can write them here. You can also add some [02:36.040 --> 02:43.240] dependencies, for example, libraries available on Ackage. Then you can use the cabal tool [02:43.240 --> 02:51.360] once we have this file, so we can run cabal build to build our targets. When you do that, [02:51.360 --> 02:58.240] cabal will get the dependencies from Ackage and run the compiler to build all your files. [02:58.240 --> 03:04.360] We also have the cabal run command to run specific targets, and you can also give command [03:04.360 --> 03:11.400] line arguments if your program requires that. We have a repo, which is a read-eval-print [03:11.400 --> 03:17.440] loop. This runs the compiler in interpreter mode, so you can write some Haskell expressions, [03:17.440 --> 03:23.760] and the compiler will evaluate these expressions and print the results. It's very interesting [03:23.760 --> 03:30.280] for testing some code, and you have also more specific commands. For example, here, [03:30.280 --> 03:34.960] you can ask some information about a type, a function, or anything. [03:34.960 --> 03:41.280] Okay, so to work on a Haskell project, we can use editors like Visual Studio Code with [03:41.280 --> 03:47.800] HLS and the Haskell.haskell plugin. It's a very classic tool, so you have the file [03:47.800 --> 03:54.760] of your project. You can open them, edit them. You also have code navigation and documentation, [03:54.760 --> 04:04.040] so if I put the mouse pointer over a function, VS Code will show me the documentation of [04:04.040 --> 04:09.040] that function, and if I control-click on the function, VS Code goes to the definition [04:09.040 --> 04:15.200] of the function. We also have code compression, so VS Code tries to complete the code you [04:15.200 --> 04:24.360] are typing. We have integration of the compiler, so if there is an error in your code, VS [04:24.360 --> 04:31.120] Code will show you where is this error, and it can give you the message from the compiler. [04:31.120 --> 04:37.280] Even if your code is correct, Haskell, VS Code can help you improve your code. It can [04:37.280 --> 04:44.760] give some hints to refactor it. For example, here, it says that my code is correct, but [04:44.760 --> 04:51.240] it would be better if I use the FMAP operator instead of the FMAP function. We also have [04:51.240 --> 04:57.120] HLS, which is, let's say you are writing some code, and you don't know what to write at [04:57.120 --> 05:03.280] a specific pace. You can put this underscore character, and the compiler will tell you what [05:03.280 --> 05:08.360] you'd expect at this pace. For example, here, it says that it waits for a function that [05:08.360 --> 05:17.400] takes a string and returns an int. We have an inline ripple, so you can type some Haskell [05:17.400 --> 05:23.800] expressions as commands in your code with a specific prefix. When you do that, VS Code [05:23.800 --> 05:29.160] will print a button, it will show a button, and if you click on this button, it will evaluate [05:29.160 --> 05:36.800] your expressions and add the result of these expressions in the comments below. It can be [05:36.800 --> 05:44.840] very useful for adding some examples as commands in your code for documenting the code. [05:44.840 --> 05:48.640] Speaking of documentation, we have Hadock, which is a classic tool where we write the [05:48.640 --> 05:56.840] documentation of our project as commands inside the code, and then we can run kbalhadock, [05:56.840 --> 06:02.600] and this generates the documentation as HTML5, which looks like this. As you can see, it's [06:02.600 --> 06:10.000] a tool that is used for generating the documentation on the package. Finally, we have some tools [06:10.000 --> 06:17.640] for testing our project. First of all, Haskell has a quite powerful type system, so it already [06:17.640 --> 06:23.280] prevents us from writing many errors, but we still need to test our code. We can do that [06:23.280 --> 06:28.000] with a very classic unit test. For example, here, we just write a Haskell expression with [06:28.000 --> 06:34.920] a specific input, and we call a function on that input, and we can write the value that [06:34.920 --> 06:42.920] we expect for this input. So we can write many inputs to test and test many functions, [06:42.920 --> 06:49.520] and when we run a kbalh test, this will compile our testing program and run it, and it checks [06:49.520 --> 06:57.280] that every expression is evaluated and returns the expected value. If there is a problem [06:57.280 --> 07:06.720] in one of the tests, a kbalh test will tell us which function fails. We have more than [07:06.720 --> 07:13.400] that. We can use property-based testing. Instead of giving a specific input, we can write a [07:13.400 --> 07:17.480] property, which is a function that takes an argument, and return a Boolean. This Boolean [07:17.480 --> 07:23.480] says if the property is satisfied or not. And when we do that, QuickChat will generate [07:23.480 --> 07:30.480] random inputs. Here, it says that it has generated 100 inputs, and it tests the properties on [07:30.480 --> 07:39.480] each input. If one input makes the test fail, QuickChat will try to shrink the input to the [07:39.480 --> 07:47.480] smallest value, such that it's simpler for us to debug our program. [07:47.480 --> 07:53.480] To conclude, Haskell has done some nice tools for many years. All these tools, kbalh, Ripple, [07:53.480 --> 08:00.080] QuickChat are quite old and now very mature. Since more recently, we have very nice integrations [08:00.080 --> 08:08.080] in editors like VSCode or other editors. This is quite easy to install, at least on Linux. [08:08.080 --> 08:13.320] You just have to install VSCode, VSCode, and Haskell.Haskell.Pagin, and that's it. You [08:13.320 --> 08:20.320] have a nice Haskell environment for developing your project. This slide and the culture here [08:20.320 --> 08:28.320] are available at this link. You can also see the tooling below, which presents other alternatives. [08:28.320 --> 08:36.320] If you prefer to use VIM or MX, there is a tool you can use to do that. And that's all [08:36.320 --> 08:38.320] for me. Thank you for your attention. [08:38.320 --> 08:53.320] Thank you very much, Julia. There is time for questions. Five minutes. Just shout it out [08:53.320 --> 08:55.320] and we can repeat the question. [08:55.320 --> 09:10.320] Can you please repeat the question? [09:10.320 --> 09:15.320] What is the difference between the kbalh Ripple and the GHTI, which is the Ripple from the [09:15.320 --> 09:22.320] compiler? In fact, I think it's quite the same tool. Kbalh will call the GHTI, the Ripple [09:22.320 --> 09:29.320] from the compiler. But if you project some specific dependencies or some modules, the [09:29.320 --> 09:34.320] kbalh Ripple will take all of that into account so you can inspect that code and quite more [09:34.320 --> 09:45.320] powerful. But it's the same tool at the end. [09:45.320 --> 09:50.320] Which tools do you recommend for debugging Haskell? [09:50.320 --> 09:56.320] I don't use very much the Askell debugger. The debugging in Haskell is quite different [09:56.320 --> 10:05.320] from other languages, I think. So there is a debugger where you can inspect memory or [10:05.320 --> 10:15.320] the runtime system using the compiler. It's not something that I can do very well. [10:15.320 --> 10:25.320] So I won't recommend anything. [10:25.320 --> 10:34.320] In your examples, you showed that you can have comments evaluated as a Ripple. [10:34.320 --> 10:40.320] I know Rust has something quite similar and it made sure that examples in your documentation [10:40.320 --> 10:46.320] have tests. Can you do similar sorts of things? [10:46.320 --> 10:55.320] You had an example of a Ripple evaluated in comments in your code. [10:55.320 --> 10:56.320] This one. [10:56.320 --> 11:01.320] Is that specifically the VS Code extension? [11:01.320 --> 11:11.320] I think so. It's provided by Visual Studio Code with the Askell extension and it's automatic. [11:11.320 --> 11:21.320] Yeah, Rust has this feature. The evaluator is doing the test for you. [11:21.320 --> 11:35.320] Yeah, so what is very confusing for beginners sometimes, if you come from another language [11:35.320 --> 11:39.320] like Rust or so, then it's one way to build a project. [11:39.320 --> 11:48.320] In Haskell, you have like Carbal and Nix together and then you have Carbal v1, v2, new. [11:48.320 --> 12:00.320] Is there some plan to clean this up someday to give a simple way to build a Haskell project? [12:00.320 --> 12:04.320] In fact, Carbal and Stack doesn't do exactly the same. [12:04.320 --> 12:11.320] Stack is based on snapshots, so it's more secure if you want to have the same build for every project. [12:11.320 --> 12:18.320] But both tools are compatible, so Stack can use the Carbal file, so you can just write a Carbal file, [12:18.320 --> 12:24.320] then add the version of the snapshots you want to use for Stack and that's it. [12:24.320 --> 12:37.320] But I agree with you, there are many tools. [12:37.320 --> 12:43.320] I'm not familiar with Stack, but I thought that Carbal has something like log file nowadays, like a freeze. [12:43.320 --> 12:45.320] Is that similar to that? [12:45.320 --> 12:49.320] Carbal, a freeze. [12:49.320 --> 13:04.320] Nix with Carbal, so there is a freeze with Nix, but I don't use Carbal very much. [13:04.320 --> 13:08.320] Okay, we're out of time, so please once again thank Julio.