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 ::
| Command | Aliases | Description |
|---|---|---|
:help [topic] | :h, :? | Show help information |
:quit | :q, :exit | Exit the REPL |
:clear | :cls | Clear the screen |
:reset | Reset all REPL state | |
:type <expr> | :t | Show the type of an expression |
:info <name> | :i | Show information about a name |
:env [filter] | :e | Show environment (vars/fns/types) |
:modules | :mods | List available and imported modules |
:exports <module> | :exp | Show what a module exports |
:delete <name> | :del, :undef | Delete a name from scope |
:load <file> | :l | Load and evaluate a file |
:reload | :r | Reload the last loaded file |
:history [pattern] | :hist | Show 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> | :bc | Show bytecode for an expression |
:tutorial | :tut | Start 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
| Shortcut | Action |
|---|---|
Tab | Trigger completion menu |
Up/Down | Navigate history |
Alt+Enter | Insert newline (multi-line input) |
Shift+Enter | Insert newline (multi-line input) |
Ctrl+C | Cancel current input |
Ctrl+D | Exit 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.