Editing Haskell source code

Keyboard Shortcuts

The interactive interpreter is a great tool, but we're not going to be able to write longer programs without breaking your text editor. In this video, you'll look at how to use GHCi along with your source code files.

- [Instructor] In this video, we're going to look…at editing Haskell source code.…We're going to see how to create a Haskell source file,…how to write a main function.…First of all, we'll interact with the interpreter, ghci,…and then we'll move onto compiling the code…using ghc.…So the first thing to do would be to open…a text file.…I'm going to call it test.hs, hs is the extension…we typically use for Haskell files.…

There's very little boilerplate that you need…to get started with the Haskell file.…You can simply create a main function,…and that's it.…If we now open up the Haskell interpreter,…we can load this file…and simply run the function.…A function declared as main is special to Haskell…and ghc gives you the option of running colon main.…

Haskell is expecting this kind of function…to be of a specific type.…Let's have a look.…Here we see that the main function has to be…an IO function, which means that it will be…doing input and output, and that it has…no return value, which is the meaning…of the empty parentheses.…

Resume Transcript Auto-Scroll

Author

Released

6/26/2017

Get started with Haskell, a functional programming language which—while it has a reputation for being a bit academic—can be practical and easy to learn. In this hands-on course, learn the basics of Haskell. Hakim Cassimally shows how to install and set up Haskell, and helps you get a feel for what this language can do by exploring Haskell using an interactive interpreter. Plus, he helps you apply what you've learned about functions and data types to create, set up, and polish a full project—a word game.

Note: This course was created by Packt Publishing. We are pleased to host this training in our library.