Okay, so here is a quick overview of Haskell today. I am Julien DeRos, I am an assistant
professor in computer science, and I use Haskell since 2015 initially for teaching
functional programming. So since the beginning of the language, Haskell has many tools that
have been created for developing in Haskell, and today most of the Haskell developers use
GHC compiler for building Haskell projects. We have a nice tool such as a cabal or stack.
Haskell is now quite well integrated in editors such as Visual Studio Code, Veeam or Emacs,
thanks to LSP implementations such as HLS, and all these tools can be installed using some tools
like GHC or Nix. In this talk, I will focus on cabal with VS Code and the Haskell plugin.
First, we have some online tools such as a package, which is a package archive,
so you can go to the website and search for packages. There is for example some
libraries for doing whatever you want. These libraries, you can access their documentation so
you can see what to do with this library and how to use it, and you also have access to their
source code, with nice colors and code navigation, which is quite useful. We also have
Google, which is Haskell Google, so it's a search engine, and you can type the name of a function,
and Google will give you a link to the documentation of that function in the package. If you don't
know the name of the function, you can also type, write the type of the function, and Google
try to find a function that matches that type, so you can see its documentation on the package,
and you can see if it's the function you are looking for. To work on a Haskell project,
you can use cabal, which is a tool for building and packaging projects. To use cabal, we have
to write a cabal file, which is a configuration file, where you can specify some information
about your project, and also define the target you want to build in your project. For example,
if you have a library or executables, you can write them here. You can also add some
dependencies, for example, libraries available on Ackage. Then you can use the cabal tool
once we have this file, so we can run cabal build to build our targets. When you do that,
cabal will get the dependencies from Ackage and run the compiler to build all your files.
We also have the cabal run command to run specific targets, and you can also give command
line arguments if your program requires that. We have a repo, which is a read-eval-print
loop. This runs the compiler in interpreter mode, so you can write some Haskell expressions,
and the compiler will evaluate these expressions and print the results. It's very interesting
for testing some code, and you have also more specific commands. For example, here,
you can ask some information about a type, a function, or anything.
Okay, so to work on a Haskell project, we can use editors like Visual Studio Code with
HLS and the Haskell.haskell plugin. It's a very classic tool, so you have the file
of your project. You can open them, edit them. You also have code navigation and documentation,
so if I put the mouse pointer over a function, VS Code will show me the documentation of
that function, and if I control-click on the function, VS Code goes to the definition
of the function. We also have code compression, so VS Code tries to complete the code you
are typing. We have integration of the compiler, so if there is an error in your code, VS
Code will show you where is this error, and it can give you the message from the compiler.
Even if your code is correct, Haskell, VS Code can help you improve your code. It can
give some hints to refactor it. For example, here, it says that my code is correct, but
it would be better if I use the FMAP operator instead of the FMAP function. We also have
HLS, which is, let's say you are writing some code, and you don't know what to write at
a specific pace. You can put this underscore character, and the compiler will tell you what
you'd expect at this pace. For example, here, it says that it waits for a function that
takes a string and returns an int. We have an inline ripple, so you can type some Haskell
expressions as commands in your code with a specific prefix. When you do that, VS Code
will print a button, it will show a button, and if you click on this button, it will evaluate
your expressions and add the result of these expressions in the comments below. It can be
very useful for adding some examples as commands in your code for documenting the code.
Speaking of documentation, we have Hadock, which is a classic tool where we write the
documentation of our project as commands inside the code, and then we can run kbalhadock,
and this generates the documentation as HTML5, which looks like this. As you can see, it's
a tool that is used for generating the documentation on the package. Finally, we have some tools
for testing our project. First of all, Haskell has a quite powerful type system, so it already
prevents us from writing many errors, but we still need to test our code. We can do that
with a very classic unit test. For example, here, we just write a Haskell expression with
a specific input, and we call a function on that input, and we can write the value that
we expect for this input. So we can write many inputs to test and test many functions,
and when we run a kbalh test, this will compile our testing program and run it, and it checks
that every expression is evaluated and returns the expected value. If there is a problem
in one of the tests, a kbalh test will tell us which function fails. We have more than
that. We can use property-based testing. Instead of giving a specific input, we can write a
property, which is a function that takes an argument, and return a Boolean. This Boolean
says if the property is satisfied or not. And when we do that, QuickChat will generate
random inputs. Here, it says that it has generated 100 inputs, and it tests the properties on
each input. If one input makes the test fail, QuickChat will try to shrink the input to the
smallest value, such that it's simpler for us to debug our program.
To conclude, Haskell has done some nice tools for many years. All these tools, kbalh, Ripple,
QuickChat are quite old and now very mature. Since more recently, we have very nice integrations
in editors like VSCode or other editors. This is quite easy to install, at least on Linux.
You just have to install VSCode, VSCode, and Haskell.Haskell.Pagin, and that's it. You
have a nice Haskell environment for developing your project. This slide and the culture here
are available at this link. You can also see the tooling below, which presents other alternatives.
If you prefer to use VIM or MX, there is a tool you can use to do that. And that's all
for me. Thank you for your attention.
Thank you very much, Julia. There is time for questions. Five minutes. Just shout it out
and we can repeat the question.
Can you please repeat the question?
What is the difference between the kbalh Ripple and the GHTI, which is the Ripple from the
compiler? In fact, I think it's quite the same tool. Kbalh will call the GHTI, the Ripple
from the compiler. But if you project some specific dependencies or some modules, the
kbalh Ripple will take all of that into account so you can inspect that code and quite more
powerful. But it's the same tool at the end.
Which tools do you recommend for debugging Haskell?
I don't use very much the Askell debugger. The debugging in Haskell is quite different
from other languages, I think. So there is a debugger where you can inspect memory or
the runtime system using the compiler. It's not something that I can do very well.
So I won't recommend anything.
In your examples, you showed that you can have comments evaluated as a Ripple.
I know Rust has something quite similar and it made sure that examples in your documentation
have tests. Can you do similar sorts of things?
You had an example of a Ripple evaluated in comments in your code.
This one.
Is that specifically the VS Code extension?
I think so. It's provided by Visual Studio Code with the Askell extension and it's automatic.
Yeah, Rust has this feature. The evaluator is doing the test for you.
Yeah, so what is very confusing for beginners sometimes, if you come from another language
like Rust or so, then it's one way to build a project.
In Haskell, you have like Carbal and Nix together and then you have Carbal v1, v2, new.
Is there some plan to clean this up someday to give a simple way to build a Haskell project?
In fact, Carbal and Stack doesn't do exactly the same.
Stack is based on snapshots, so it's more secure if you want to have the same build for every project.
But both tools are compatible, so Stack can use the Carbal file, so you can just write a Carbal file,
then add the version of the snapshots you want to use for Stack and that's it.
But I agree with you, there are many tools.
I'm not familiar with Stack, but I thought that Carbal has something like log file nowadays, like a freeze.
Is that similar to that?
Carbal, a freeze.
Nix with Carbal, so there is a freeze with Nix, but I don't use Carbal very much.
Okay, we're out of time, so please once again thank Julio.