.. _sect-repl: ************** The Idris REPL ************** Idris comes with a ``REPL``. Evaluation ========== Being a fully dependently typed language, Idris has two phases where it evaluates things, compile-time and run-time. At compile-time it will only evaluate things which it knows to be total (i.e. terminating and covering all possible inputs) in order to keep type checking decidable. The compile-time evaluator is part of the Idris kernel, and is implemented in Haskell using a HOAS (higher order abstract syntax) style representation of values. Since everything is known to have a normal form here, the evaluation strategy doesn't actually matter because either way it will get the same answer, and in practice it will do whatever the Haskell run-time system chooses to do. The REPL, for convenience, uses the compile-time notion of evaluation. As well as being easier to implement (because we have the evaluator available) this can be very useful to show how terms evaluate in the type checker. So you can see the difference between: .. code-block:: idris Idris> \n, m => (S n) + m \n => \m => S (plus n m) : Nat -> Nat -> Nat Idris> \n, m => n + (S m) \n => \m => plus n (S m) : Nat -> Nat -> Nat Customisation ============= Idris supports initialisation scripts. Initialisation scripts ~~~~~~~~~~~~~~~~~~~~~~ When the Idris REPL starts up, it will attempt to open the file repl/init in Idris's application data directory. The application data directory is the result of the Haskell function call ``getAppUserDataDirectory "idris"``, which on most Unix-like systems will return $HOME/.idris and on various versions of Windows will return paths such as ``C:/Documents And Settings/user/Application Data/appName``. The file repl/init is a newline-separate list of REPL commands. Not all commands are supported in initialisation scripts — only the subset that will not interfere with the normal operation of the REPL. In particular, setting colours, display options such as showing implicits, and log levels are supported. Example initialisation script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :: :colour prompt white italic bold :colour implicit magenta italic The ``REPL`` Commands ===================== The current set of supported commands are: +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |Command | Arguments | Purpose | +================+==============================+==========================================================================================================+ | | | Evaluate an expression | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:t :type | | Check the type of an expression | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:core | | View the core language representation of a term | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:miss :missing | | Show missing clauses | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:doc | | Show internal documentation | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:mkdoc | | Generate IdrisDoc for namespace(s) and dependencies | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:apropos | [] | Search names, types, and documentation | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:s :search | [] | Search for values by type | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:wc :whocalls | | List the callers of some name | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:cw :callswho | | List the callees of some name | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:browse | | List the contents of some namespace | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:total | | Check the totality of a name | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:r :reload | | Reload current file | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:l :load | | Load a new file | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:cd | | Change working directory | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:module | | Import an extra module | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:e :edit | | Edit current file using $EDITOR or $VISUAL | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:m :metavars | | Show remaining proof obligations (holes) | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:p :prove | | Prove a hole | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:a :addproof | | Add proof to source file | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:rmproof | | Remove proof from proof stack | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:showproof | | Show proof | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:proofs | | Show available proofs | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:x | | Execute IO actions resulting from an expression using the interpreter | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:c :compile | | Compile to an executable [codegen] | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:exec :execute | [] | Compile to an executable and run | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:dynamic | | Dynamically load a C library (similar to %dynamic) | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:dynamic | | List dynamically loaded C libraries | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:? :h :help | | Display this help text | +----------------+------------------------------+----------------------------------------------------------------------------------------------------------+ |:set |