# Haskell/Using GHCi effectively

* Using GHCi effectively
* Elementary Haskell
* Recursion
* Lists II (map)
* Lists III (folds, comprehensions)
* Type declarations
* Pattern matching
* Control structures
* More on functions
* Higher-order functions
* Using GHCi effectively
GHCi assists in several ways toward more efficient work. Here, we will discuss some of the best practices for using GHCi.

## User interface
### Tab completion

As in many other terminal programs, you can enter some starting text in GHCi and then hit the Tab key to be presented with a list of all possibilities that start with what you've written so far. When there is only one possibility, using Tab will auto-complete the string. For example fol<Tab> will append letter "d" (since nothing exists with "fol" other than items that start with "fold"). A second Tab will list the four functions included in Prelude: foldl, foldl1, foldr, and foldr1. More options may show if you have already imported additional modules.
Tab completion works also when you are loading a file with your program into GHCi. For example, after typing :l fi<Tab>, you will be presented with all files that start with "fi" that are present in the current directory (the one you were in when you launched GHCi).
The same also applies when you are importing modules, after typing :m +Da<Tab> or import Da<Tab>, you will be presented with all modules that start with "Da" present in installed packages.

### ": commands"

On GHCi command line, commands for the interpreter start with the character ":" (colon).
* :help or :h -- prints a list of all available commands.
* :load or :l -- loads a given file into GHCi (you must include the filename with the command).
* :reload or :r -- reloads whatever file had been loaded most recently (useful after changes to the file).
* :type or :t -- prints the type of a given expression included with the command
* :module or :m -- loads a given module (include the module name with the command). You can also unload a module by adding a - symbol before the module name.
* :browse -- gives the type signatures for all functions available from a given module.
Here again, you can use Tab to see the list of commands, type :Tab to see all possible commands.

### Timing Functions in GHCi

GHCi provides a basic way to measure how much time a function takes to run, which can be useful for to find out which version of a function runs fastest (such as when there are multiple ways to define something to get the same effective result).
* Type :set +s into the ghci command line.
* run the function(s) you are testing. The time the function took to run will be displayed after GHCi outputs the results of the function.

### Multi-line Input

If you are trying to define a function that takes up multiple lines, or if you want to type a do block into ghci (without writing a file that you then import), there is an easy way to do this:
* Begin a new line with :{
* Type in your code. Press enter when you need a new line.
* Type :} to end the multi-line input.
For example:
The same can be accomplished by using :set +m command (allow multi-line commands). In this case, an empty line will end the block.
In addition, line breaks in ghci commands can be separated by ;, like this:
* Using GHCi effectively
* Elementary Haskell
* Recursion
* >> Lists II (map)
* >> Lists III (folds, comprehensions)
* >> Type declarations
* >> Pattern matching
* >> Control structures
* >> More on functions
* >> Higher-order functions
* >> Using GHCi effectively
* Haskell
* Haskell Basics
* >> Elementary Haskell
* >> Intermediate Haskell
* >> Monads
* Advanced Haskell
* >> Fun with Types
* >> Wider Theory
* >> Haskell Performance
* Libraries Reference
* >> General Practices
* >> Specialised Tasks