Haskell is a functional programming language.
The Haskell programming language hasn't had any substantial changes for the last 10 years. Most of the current implementations use the Haskell 2010 language specification.
You can download Haskell tools from the official website:
GHC
There are a few choices when you do Haskell development, but GHC is one of the most widely used tools. (In fact, it is the de facto "standard" compiler for Haskell in many respects.)
Note that the Haskell language
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.7
GHCi
The GHC distribution comes with a Haskell REPL called ghci (i for interactive):
$ ghci
GHCi, version 8.10.7: http://www.haskell.org/ghc/ :? for help
Prelude>
GHCup
GHCup is a command line tool to manage Haskell build tools such as ghc and cabal. This can be installed using a shell script as follows:
$ curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
Then, one can use the terminal UI to install/update a few different Haskell tools.
$ ghcup tui
...
Cabal
Cabal is a package and dependency management system as well as a build tool.
$ cabal --help
Command line interface to the Haskell Cabal infrastructure.
See http://www.haskell.org/cabal/ for more information.
Usage: cabal [GLOBAL FLAGS] [COMMAND [FLAGS]]
Commands:
[global]
update Updates list of known packages.
install Install packages.
help Help about commands.
info Display detailed information about a particular package.
list List packages matching a search string.
fetch Downloads packages for later installation.
user-config Display and update the user's global cabal configuration.
[package]
get Download/Extract a package's source code (repository).
init Create a new .cabal package file.
configure Add extra project configuration
build Compile targets within the project.
clean Clean the package store and remove temporary files.
run Run an executable.
repl Open an interactive session for the given component.
test Run test-suites
bench Run benchmarks
check Check the package for common mistakes.
sdist Generate a source distribution file (.tar.gz).
upload Uploads source packages or documentation to Hackage.
report Upload build reports to a remote server.
freeze Freeze dependencies.
gen-bounds Generate dependency bounds.
outdated Check for outdated dependencies
haddock Build Haddock documentation
hscolour Generate HsColour colourised code, in HTML format.
exec Give a command access to the store.
list-bin list path to a single executable.
For more information about a command use:
cabal COMMAND --help
or cabal help COMMAND
To install Cabal packages from hackage use:
cabal install foo [--dry-run]
Occasionally you need to update the list of available packages:
cabal update
Global flags:
-h, --help Show this help text
-V, --version Print version information
--numeric-version Print just the version number
--config-file=FILE Set an alternate location for the config file
--default-user-config=FILE Set a location for a cabal.config file for
projects without their own cabal.config freeze
file.
--ignore-expiry Ignore expiry dates on signed metadata (use
only in exceptional circumstances)
--http-transport=HttpTransport
Set a transport for http(s) requests. Accepts
'curl', 'wget', 'powershell', and
'plain-http'. (default: 'curl')
--enable-nix Enable Nix integration: run commands through
nix-shell if a 'shell.nix' file exists
--disable-nix Disable Nix integration: run commands through
nix-shell if a 'shell.nix' file exists
You can edit the cabal configuration file to set defaults:
/home/harry/.cabal/config
Alternatively, one can you stack instead of cabal-build. For example,
$ stack --help
stack - The Haskell Tool Stack
Usage: stack [--help] [--version] [--numeric-version] [--hpack-numeric-version]
[--docker*] [--nix*]
[--verbosity VERBOSITY | (-v|--verbose) | --silent]
[--[no-]time-in-log] [--stack-root STACK-ROOT]
[--work-dir WORK-DIR] [--[no-]system-ghc] [--[no-]install-ghc]
[--arch ARCH] [--ghc-variant VARIANT] [--ghc-build BUILD]
[-j|--jobs JOBS] [--extra-include-dirs DIR] [--extra-lib-dirs DIR]
[--custom-preprocessor-extensions EXT] [--with-gcc PATH-TO-GCC]
[--with-hpack HPACK] [--[no-]skip-ghc-check] [--[no-]skip-msys]
[--local-bin-path DIR] [--setup-info-yaml URL]
[--[no-]modify-code-page] [--[no-]allow-different-user]
[--[no-]dump-logs] [--color|--colour WHEN]
[--snapshot-location-base URL] [--resolver RESOLVER]
[--compiler COMPILER] [--[no-]terminal]
[--stack-colors|--stack-colours STYLES] [--terminal-width INT]
[--stack-yaml STACK-YAML] [--lock-file ARG] COMMAND|FILE
Available options:
--help Show this help text
--version Show version
--numeric-version Show only version number
--hpack-numeric-version Show only hpack's version number
--docker* Run 'stack --docker-help' for details
--nix* Run 'stack --nix-help' for details
--verbosity VERBOSITY Verbosity: silent, error, warn, info, debug
-v,--verbose Enable verbose mode: verbosity level "debug"
--silent Enable silent mode: verbosity level "silent"
--[no-]time-in-log Enable/disable inclusion of timings in logs, for the
purposes of using diff with logs (default: enabled)
--stack-root STACK-ROOT Absolute path to the global stack root directory
(Overrides any STACK_ROOT environment variable)
--work-dir WORK-DIR Relative path of work directory (Overrides any
STACK_WORK environment variable, default is
'.stack-work')
--[no-]system-ghc Enable/disable using the system installed GHC (on the
PATH) if it is available and its version matches.
Disabled by default.
--[no-]install-ghc Enable/disable downloading and installing GHC if
necessary (can be done manually with stack setup)
(default: enabled)
--arch ARCH System architecture, e.g. i386, x86_64
--ghc-variant VARIANT Specialized GHC variant, e.g. integersimple
(incompatible with --system-ghc)
--ghc-build BUILD Specialized GHC build, e.g. 'gmp4' or 'standard'
(usually auto-detected)
-j,--jobs JOBS Number of concurrent jobs to run
--extra-include-dirs DIR Extra directories to check for C header files
--extra-lib-dirs DIR Extra directories to check for libraries
--custom-preprocessor-extensions EXT
Extensions used for custom preprocessors
--with-gcc PATH-TO-GCC Use gcc found at PATH-TO-GCC
--with-hpack HPACK Use HPACK executable (overrides bundled Hpack)
--[no-]skip-ghc-check Enable/disable skipping the GHC version and
architecture check (default: disabled)
--[no-]skip-msys Enable/disable skipping the local MSYS installation
(Windows only) (default: disabled)
--local-bin-path DIR Install binaries to DIR
--setup-info-yaml URL Alternate URL or relative / absolute path for stack
dependencies
--[no-]modify-code-page Enable/disable setting the codepage to support UTF-8
(Windows only) (default: enabled)
--[no-]allow-different-user
Enable/disable permission for users other than the
owner of the stack root directory to use a stack
installation (POSIX only) (default: true inside
Docker, otherwise false)
--[no-]dump-logs Enable/disable dump the build output logs for local
packages to the console (default: dump warning logs)
--color,--colour WHEN Specify when to use color in output; WHEN is
'always', 'never', or 'auto'. On Windows versions
before Windows 10, for terminals that do not support
color codes, the default is 'never'; color may work
on terminals that support color codes
--snapshot-location-base URL
The base location of LTS/Nightly snapshots
--resolver RESOLVER Override resolver in project file
--compiler COMPILER Use the specified compiler
--[no-]terminal Enable/disable overriding terminal detection in the
case of running in a false terminal
--stack-colors,--stack-colours STYLES
Specify stack's output styles; STYLES is a
colon-delimited sequence of key=value, where 'key' is
a style name and 'value' is a semicolon-delimited
list of 'ANSI' SGR (Select Graphic Rendition) control
codes (in decimal). Use 'stack ls stack-colors
--basic' to see the current sequence. In shells where
a semicolon is a command separator, enclose STYLES in
quotes.
--terminal-width INT Specify the width of the terminal, used for
pretty-print messages
--stack-yaml STACK-YAML Override project stack.yaml file (overrides any
STACK_YAML environment variable)
--lock-file ARG Specify how to interact with lock files. Default:
read/write. If resolver is overridden: read-only
Available commands:
build Build the package(s) in this directory/configuration
install Shortcut for 'build --copy-bins'
uninstall DEPRECATED: This command performs no actions, and is
present for documentation only
test Shortcut for 'build --test'
bench Shortcut for 'build --bench'
haddock Shortcut for 'build --haddock'
new Create a new project from a template. Run `stack
templates' to see available templates. Note: you can
also specify a local file or a remote URL as a
template.
templates Show how to find templates available for `stack new'.
`stack new' can accept a template from a remote
repository (default: github), local file or remote
URL. Note: this downloads the help file.
init Create stack project config from cabal or hpack
package specifications
setup Get the appropriate GHC for your project
path Print out handy path information
ls List command. (Supports snapshots, dependencies and
stack's styles)
unpack Unpack one or more packages locally
update Update the package index
upgrade Upgrade to the latest stack
upload Upload a package to Hackage
sdist Create source distribution tarballs
dot Visualize your project's dependency graph using
Graphviz dot
ghc Run ghc
hoogle Run hoogle, the Haskell API search engine. Use the
'-- ARGUMENT(S)' syntax to pass Hoogle arguments,
e.g. stack hoogle -- --count=20, or stack hoogle --
server --local.
exec Execute a command. If the command is absent, the
first of any arguments is taken as the command.
run Build and run an executable. Defaults to the first
available executable if none is provided as the first
argument.
ghci Run ghci in the context of package(s) (experimental)
repl Run ghci in the context of package(s) (experimental)
(alias for 'ghci')
runghc Run runghc
runhaskell Run runghc (alias for 'runghc')
script Run a Stack Script
eval Evaluate some haskell code inline. Shortcut for
'stack exec ghc -- -e CODE'
clean Delete build artefacts for the project packages.
purge Delete the project stack working directories
(.stack-work by default). Shortcut for 'stack clean
--full'
query Query general build information (experimental)
list List package id's in snapshot (experimental)
ide IDE-specific commands
docker Subcommands specific to Docker use
config Subcommands for accessing and modifying configuration
values
hpc Subcommands specific to Haskell Program Coverage
stack's documentation is available at https://docs.haskellstack.org/
What's Next
Now that we have a development environment set up, let's try creating a simple program.
- Next Step: Creating the first program in Haskell
C C++ C# Clojure Crystal D Dart Erlang F# Go Java Javascript Julia Kotlin Lua Python Rust Scala Swift Typescript