Esc
Start typing to search...

Using the REPL

The Keel REPL (Read-Eval-Print Loop) provides an interactive environment for experimenting with Keel code.

Starting the REPL

Start the REPL using the unified CLI:

keel repl

Or using the standalone binary:

keel-repl

You'll see a welcome message and prompt:

keel>

Basic Usage

Enter expressions at the prompt to evaluate them:

> 1 + 2
3

> "Hello, " ++ "World!"
"Hello, World!"

> let x = 42
> x * 2
84

Auto-Imported Standard Library

All standard library modules are available immediately in the REPL without explicit imports:

  • List — Functional list operations (map, filter, foldl, foldr, length, etc.)
  • String — String manipulation (length, concat, toUpper, toLower, split, etc.)
  • Math — Mathematical functions and constants (abs, sqrt, pow, sin, cos, pi, e, etc.)
  • DateTime — Date and time operations (now, parse, format, addDays, diffHours, etc.)
  • IO — Console and file I/O (println, readFile, writeFile, etc.)
  • Http — HTTP client (get, post, send, etc.)
  • Json — JSON parsing and serialization (parse, stringify, etc.)
  • DataFrame — Data manipulation with Polars backend
  • Result — Functional error handling (map, andThen, withDefault, etc.)
  • Maybe — Optional value handling (map, andThen, withDefault, etc.)

IO and HTTP work by default in the REPL — no environment variables needed.

REPL Commands

The REPL supports special commands, all prefixed with ::

CommandAliasesDescription
:help [topic]:h, :?Show help information
:quit:q, :exitExit the REPL
:clear:clsClear the screen
:resetReset all REPL state
:type <expr>:tShow the type of an expression
:info <name>:iShow information about a name
:env [filter]:eShow environment (vars/fns/types)
:modules:modsList available and imported modules
:exports <module>:expShow what a module exports
:delete <name>:del, :undefDelete a name from scope
:load <file>:lLoad and evaluate a file
:reload:rReload the last loaded file
:history [pattern]:histShow or search command history
:timing [on|off]Toggle execution timing display
:types [on|off]Toggle type display with results
:ast <expr>Show the AST for an expression
:bytecode <expr>:bcShow bytecode for an expression
:tutorial:tutStart the interactive tutorial

Checking Types

Use :type (or :t for short) to inspect expression types:

> :type 42
Int

> :type "hello"
String

> :type |x: Int| x + 1
Int -> Int

Multi-line Input

The REPL automatically continues to the next line when:

  • Brackets are unclosed: (, [, {
  • Line ends with an operator: +, |>, >>, etc.

You can also press Alt+Enter or Shift+Enter to insert a newline, or use explicit blocks with :{ and :}:

> :{
| fn fibonacci : Int -> Int
| fn fibonacci n =
|     case n of
|         0 -> 0
|         1 -> 1
|         _ -> fibonacci (n - 1) + fibonacci (n - 2)
| :}

> fibonacci 10
55

Tab Completion

Press Tab to autocomplete:

  • Variable and function names
  • REPL commands
  • Module names
  • Module members (e.g., List.ma + Tab → List.map)
  • Keywords

Syntax Highlighting

The REPL provides syntax highlighting for keywords, types, strings, numbers, and operators as you type.

Keyboard Shortcuts

ShortcutAction
TabTrigger completion menu
Up/DownNavigate history
Alt+EnterInsert newline (multi-line input)
Shift+EnterInsert newline (multi-line input)
Ctrl+CCancel current input
Ctrl+DExit REPL

Loading Files

Load external Keel files with :load:

> :load examples/math.kl
Loaded: examples/math.kl

> square 5
25

History

The REPL maintains a persistent command history. Use the up and down arrow keys to navigate through previous entries, or use :history to search.

Online Playground

If you don't want to install Keel locally, try the online playground for a quick interactive experience.

Next Steps

Now that you're familiar with the REPL, learn about variables in detail.