Using Code from Other Modules

It’s rare to write programs that are entirely self contained. Nearly all programs that we write will depend on some some code that’s been defined elsewhere in some other module. To make use of code defined in some other module, we have to import the code from that module. When we import a module, we can get access to all of the code that it has exported. In this section, we’ll focus on using libraries, and you’ll learn how to import code from modules defined inside of libraries that you depend on. Later on in this chapter, you’ll learn how to define your own modules and control what they export.

Importing a Module

You can import a module using the import keyword. You need to write an import declaration for each ...

Get Effective Haskell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.