Using a Literate Haskell File

Many of the Haskell notes on this site are HTML renderings literate Haskell programs. That means if you open load the source text for such a page into Haskell, and all the lines beginning with > will be evalauted. All other lines will be treated as comments that Haskell will ignore.

To load one of these pages into Haskell, do the following:

  1. Download the text source for this page to your computer. The link to the source is in the “Show Source” link on the sidebar.

  2. Rename the source file you just downloaded to haskell_intro_lhs.lhs, i.e. change the extension .txt to .lhs.

    This renaming step is needed because the HTML renderer requires source files end with .txt, but literate Haskell files must end with .lhs.

  3. Launch Haskell on your computer:

    $ ghci
    
  4. Load the file into the interpreter:

    Prelude> :load filename.lhs
    

    Now you can call any of the functions defined in the file.