liveBook · Manning

Read-execute-print loop

As explained in Learn Haskell by Example

An execution mode in which program expressions or commands are entered and evaluated incrementally.

A read–eval–print loop lets you enter Haskell expressions and commands incrementally, observe their results, and prototype code before building a complete executable. section 2.0 section 2.1.2

A typical workflow is:

  • Create or enter a Stack project, then start its interactive session with `stack repl`. section 2.1.2
  • Use GHCi to load definitions from the project, including functions written in `src/Lib.hs`. section 2.1.2
  • Enter expressions, bindings, type annotations, and function definitions; each input is evaluated immediately. section 2.1.2
  • Read values and types at the prompt, while recognizing that assignments themselves produce no result. section 2.1.2

Evaluating bindings and a function

At the `ghci>` prompt, define typed values and a function, then evaluate them: `a = 1 :: Int`, `b = 2 :: Int`, `c = a + b`, `c` produces `3`; defining `square x = x * x` and evaluating `square 2` produces `4`. Multi-line definitions can be entered between `:{` and `:}`.

stack repl

Use the supplied `stack repl` command as the entry point for an interactive project session. section 2.1.2

How Learn Haskell by Example covers it

How deep it goes
Demonstrates launching GHCi, loading project definitions, evaluating expressions, binding names, annotating types, and defining functions.
Examples
Uses arithmetic bindings, typed integers, the `square` function, and multi-line definitions as interactive demonstrations.
What it assumes
Starts from a Stack-created project and introduces interactive Haskell evaluation, bindings, types, and functions from basic syntax.
What you can do after
Apply it via GHCi and Stack to evaluate expressions, test bindings, inspect types, and prototype Haskell functions.
How it connects
Connects GHCi with Stack projects, Haskell expressions, type annotations, variables, and function definitions.

Also explained in

Compare how 6 books explain read-execute-print loop →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.