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.

Installing Eta

Currently, the there are a few ways of installing Eta:

  1. Source
  2. Docker
  3. Nix

Method 1: Source Installation

Prerequisites

Make sure you have the listed tools/libraries installed on your system. Check the OS-specific sections for additional requirements.

General

  • Stack - Make sure the path that is obtained from running stack path --local-bin is present on the PATH.
  • JDK 1.7 or JDK 1.8
    • Make sure javac and java are on the PATH.

Ubuntu

  • Install bz2, ncurses, zlib.
sudo apt-get install zlib1g-dev libncurses5-dev libbz2-dev

OS X

  • Make sure you have XCode installed and have accepted the license agreement (run XCode at least once).

Windows

  • Install Cygwin and MSYS.

Note

An alternate method of installing Eta on Windows 10 is with WSL (Windows sub-system for Linux).

  1. Enable WSL within Windows (Instructions)
  2. Minimum Windows version: Version 10 build 14986
  3. Enter the root folder of WSL, and create a “.local” folder, and then inside of this create a “bin” folder.
  4. Follow the source installation method.

Installation

Clone the repository and run the install script at the root of the repository. Replace [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

Note

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

Prerequisites

Make sure you have the following tools installed on your system:

Installation

To obtain an environment with eta and etlas, run the following command:

docker run -it typelead/eta

Method 3: Nix

Prerequisites

Make sure you have the following tools installed on your system:

Installation

To obtain an environment with eta and etlas, run the following command:

nix-shell -A eta-build-shell

Updating 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

  1. Create a new file called Main.hs and 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)
    
  2. Run the following command on the command line to compile the program:

    eta Main.hs
    

    This will compile the program to a standalone JAR with the Run- prefix.

  3. 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 sent 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 this guide.

  1. Create a new directory called eta-first and enter it.

    mkdir eta-first
    cd eta-first
    
  2. Initialize the project with Etlas.

    etlas init
    

    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
    
  3. Add the files Main.hs and Primes.hs in src/ as shown below.

    Main.hs

    module Main where
    
    import Primes
    
    main = putStrLn $ "The 101st prime is " ++ show (primes !! 100)
    

    Primes.hs

    module Primes where
    
    primes = filterPrime [2..]
      where filterPrime (p:xs) =
              p : filterPrime [x | x <- xs, x `mod` p /= 0]
    
  4. Update eta-first.cabal, adding an other-modules: field:

    other-modules: Primes
    

    Any additional modules you add to the project should be added at the same indentation level as the Primes entry, but below it.

  5. To build & run, execute this command:

    etlas run
    

    Note

    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.

Learning Eta

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:

For tutorials & examples, see the following:

For a list of the currently supported packages, see:

Contact Us

If you had trouble with this tutorial, you can give us feedback by: