scalaz-guide / intro.rst


This is an introduction to Scalaz (pronounced "scala-zed"). Quoting the scalaz documentation:

Scalaz is a library written in the Scala Programming Language. The intention of Scalaz is to include general functions that are not currently available in the core Scala API. The scalaz-core module depends only on the core Scala API and the core Java 2 Standard Edition API.

I think one of the parts the introduction above misses out on is that Scalaz is substantially influenced by Haskell types and attempts to carryover some of its features into scala. It goes without saying that scalaz is very strongly influenced towards functional programming constructs.


At the point in time this tutorial has been written scalaz current version is 0.5.0

Getting Started

The scalaz site is located at The source code repository is available at

Getting the source

Make sure you have git installed. If not you shall need to do download and install the same. Most linux versions should have the same available for install through the distribution's packaging system such as apt or yum. Alternative download and install the same as per instructions on the website.

Now check out scalaz using the following command:

user:/home/user$ git clone

You will also need sbt: the simple build tool for scala. the scala build tool to be installed.

Change your working directory (or cd into) the directory where you cloned or retrieved the scalaz code from github. (The directory will be called scalaz)

user:/home/user$ cd scalaz

Compiling, building and launching the console for sbt.

Also now run sbt to build the same

user:/home/user$ sbt

sbt will compile/build scalaz and revert control to you in a prompt mode. (sample session shown below)

> help
You may execute any project action or one of the commands described below. Only one action may be executed at a time in interactive mode and is entered by name, as it would be at the command line. Also, tab completion is available.
Available Commands:
  <action name> : Executes the project specified action.
  <method name> <parameter>* : Executes the project specified method.
  <processor label> <arguments> : Runs the specified processor.
  ~ <command> : Executes the project specified action or method whenever source files change.
  < file : Executes the commands in the given file.  Each command should be on its own line.  Empty lines and lines beginning with '#' are ignored
  + <command> : Executes the project specified action or method for all versions of Scala defined in crossScalaVersions.
  ++<version> <command> : Changes the version of Scala building the project and executes the provided command.  <command> is optional.
  * : Prefix for commands for managing processors.  Run '*help' for details.
  ! : Prefix for history commands.  Run '!' for history command help.
  actions : Shows all available actions.
  reload : Reloads sbt, picking up modifications to sbt.version or scala.version and recompiling modified project definitions.
  help : Displays this help message.
  current : Shows the current project, Scala version, and logging level.
  debug, info, warn, error : Set logging for the current project to the specified level.
  trace 'on', 'nosbt', 'off', or <integer> : Configures stack trace logging. 'nosbt' prints stack traces up to the first sbt frame.  An integer gives the number of frames to show per exception.
  project <project name> : Sets the currently active project.
  projects : Shows all available projects.
  exit, quit : Terminates the build.
  set <property> <value> : Sets the value of the property given as its argument.
  get <property> : Gets the value of the property given as its argument.
  console-project : Enters the Scala interpreter with the current project definition bound to the variable 'current' and all members imported.
  builder : Set the current project to be the project definition builder.

Change project to scalaz:

> project scalaz-core
Set current project to scalaz-core 5.1-SNAPSHOT

Start console:

> console
[info] == clean src_managed ==
[info] Deleting directory /home/user/scalaz/core/src_managed/main/scala
[info] == clean src_managed ==
[info] == generate-tuple-w ==
[info] == generate-tuple-w ==
[info] == compile ==
[info]   Source analysis: 0 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling main sources...
[info] Nothing to compile.
[info]   Post-analysis: 3361 classes.
[info] == compile ==
[info] == copy-test-resources ==
[info] == copy-test-resources ==
[info] == test-compile ==
[info]   Source analysis: 0 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling test sources...
[info] Nothing to compile.
[info]   Post-analysis: 0 classes.
[info] == test-compile ==
[info] == copy-resources ==
[info] == copy-resources ==
[info] == console ==
[info] Starting scala interpreter...
import scalaz._
import Scalaz._
Welcome to Scala version (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.


If you reach here, you've successfuly downloaded and built scalaz and now can use the same through the scala interpreter just launched. To exit the interpreter, just type :quit at the prompt.