Getting Started with Eta¶
In the following sections, we’ll cover how to get Eta installed on your system and how to work with Etlas projects. If at any point you get stuck with any of the steps below, feel free to join us on Gitter so we can help you troubleshoot.
Currently, the there are a few ways of installing Eta:
Method 1: Source Installation¶
Make sure you have the listed tools/libraries installed on your system. Check the OS-specific sections for additional requirements.
sudo apt-get install zlib1g-dev libncurses5-dev libbz2-dev
- Make sure you have XCode installed and have accepted the license agreement (run XCode at least once).
An alternate method of installing Eta on Windows 10 is with WSL (Windows sub-system for Linux).
- Enable WSL within Windows (Instructions)
- Minimum Windows version: Version 10 build 14986
- Enter the root folder of WSL, and create a “.local” folder, and then inside of this create a “bin” folder.
- Follow the source installation method.
Clone the repository and run the install script at the root of the repository.
[current-stable-tag] with the tag listed in the README of the eta repo.
git clone --recursive --branch [current-stable-tag] https://github.com/typelead/eta cd eta ./install.sh # or install.cmd in windows command prompt
If you omit the –recursive flag to git clone, you will need to initialize the project’s submodules before running install.sh or install.cmd:
git submodule update --init --recursive
Once the installation is done, you will now have access to the following command-line tools:
eta- The main compiler
etlas- The package manager and build tool
Check to ensure that they are on the
PATH with the following commands:
eta --version etlas --version
If you obtain an error that either tool is missing, run the following command:
stack path --local-bin
Add the path that you obtain in the output to your
PATH environment variable.
Method 2: Docker¶
To obtain an environment with
etlas, run the following command:
docker run -it typelead/eta
Eta updates pretty fast and we’re incorporating new patches on a daily basis that you might want to get access to.
If you have Eta already installed, go to the root of this repository’s clone on your system, and run the following command:
./update.sh # or update.cmd in windows command prompt
This will do a fresh installation, recompiling all the core libraries with the most recent version of the compiler.
If you have existing Etlas projects, make sure you run
etlas clean etlas install --dependencies-only
inside each project before proceeding with your normal development so that Etlas recognizes the updated libraries.
Running Your First Program¶
Create a new file called
Main.hsand with the following contents:
module Main where primes = filterPrime [2..] where filterPrime (p:xs) = p : filterPrime [x | x <- xs, x `mod` p /= 0] main = putStrLn $ "The 101st prime is " ++ show (primes !! 100)
Run the following command on the command line to compile the program:
This will compile the program to a standalone JAR with the
Run the program with java:
java -jar RunMain.jar
Setting up your first Etlas Project¶
With Etlas, you don’t have to worry about remembering all the particular flags to
eta. You can simply specify what you want in a human-readable format
called Cabal. To learn more about the specification file format which is also used
in the Haskell ecosystem, read
Create a new directory called
eta-firstand enter it.
mkdir eta-first cd eta-first
Initialize the project with Etlas.
This is an interactive command that will ask you questions and help you generate a Cabal project file for your project.
- Package name - Press enter to select the default.
- Package version - Press enter to select the default.
- License - Press enter to select the default.
- Author name - Press enter to select the default.
- Maintainer email - Press enter to select the default.
- Project homepage URL - Press enter to select the default.
- Project synopsis - Press enter to select the default.
- Project category - Press enter to select the default.
- Package build - Press 2 to select Executable.
- Main module - Press enter to select the default.
- Base language - Press enter to select the default.
- Inline documentation - Press enter to select the default.
- Source directory - Press 2 to select src.
The project structure should look like this:
eta-first/ |--src/ |----Main.hs |--ChangeLog.md |--LICENSE |--eta-first.cabal |--Setup.hs
Add the files
src/as shown below.
module Main where import Primes main = putStrLn $ "The 101st prime is " ++ show (primes !! 100)
module Primes where primes = filterPrime [2..] where filterPrime (p:xs) = p : filterPrime [x | x <- xs, x `mod` p /= 0]
eta-first.cabal, adding an
Any additional modules you add to the project should be added at the same indentation level as the
Primesentry, but below it.
To build & run, execute this command:
Note that this will create a JAR file without dependencies. This is best suited for development.
For production deployments, you may want to generate a standalone JAR file, also called an uberjar. If you would like to generate an uberjar, run the following two commands:
etlas clean etlas configure --enable-uberjar-mode
These commands need only be run once to set the local Etlas configuration. To go back to shared mode for the project:
etlas clean etlas configure --disable-uberjar-mode
Beware that this can be very slow. Work is being done to improve uberjar performance.
Now that you’re set up with Eta, the next step is to learn about how to write Eta programs. If you are already familiar with haskell you can jump straight to the Interacting with Java section in Eta Tutorials to learn about how to connect with Java libraries.
If you are new to Haskell and pure functional programming in general, we suggest the following resources to get you started with the basics:
- Learn You a Haskell in a Nutshell
- Functional Programming By Example
- Learn You a Haskell
- Real World Haskell
For tutorials & examples, see the following:
- Eta Tutorials
- Eta 2048 Game Implementation
- JDBC Example
- Neo4j Example
- Kafka Client
- Kafka Conduit
- Repository of Eta Examples
For a list of the currently supported packages, see: