I’m studying the source code of the scalaz project as a way to introduce myself to Scala (and category theory in general). Reading a source code has always been considered a constructive approach to learn a language provided the project is of importance to the community (behind the language) and is developed with care. I think scalaz is of great importance to the Scala community and can be quite useful to learn the language.
I’ve found the question Good scalaz introduction [closed] on StackOverflow where I could find some pointers to articles and videos about scalaz. That’s how I stumbled upon the video Scalaz Presentation – Nick Partridge. It’s quickly turned out very useful. I highly recommend watching it.
At 00:38:07 Nick shows the slide with two imports:
It took me a while to understand their meaning, even after Nick explained it well (but it became so after I spent a while to think about it).
The first import (with scalaz written with the lowercase s) is to import all the members of the
scalaz package while the other (with Scalaz with the uppercase S) is to import the members of the
scalaz.Scalaz object. Two different namespaces and different “artifacts” loaded. It might be quite surprising for newcomers to Scala (it certainly was for me).
See the below sample session with Java’s java.util.concurrent package to learn about “import stacks” in Scala, e.g. how one import can shorten the other (given they’re in scope).
Welcome to Scala version 2.10.2 (Java HotSpot(TM) Client VM, Java 1.7.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import java.util._
scala> import concurrent._
I needed an environment where I could do the same with scalaz.
But I didn’t mean to spend hours completing CLASSPATH. I bet you don’t, either.
So if you’re keen to give scalaz a try without having to worry about transitive dependencies to feed them in to Scala REPL (by expanding its CLASSPATH), use sbt. Scala Build Tool (sbt) can manage dependencies for you.
I assume you’ve got sbt installed already. Unless you have, follow the official Installing sbt.
With sbt available, create a project directory and then
build.sbt with the following content:
version := "1.0"
scalaVersion := "2.10.2"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.0-M1"
Please note that the empty lines between sbt properties are required.
You may replace the version of scalaz from
7.0.2 if you need the latest stable one.
sbt console, do
import scalaz._, Scalaz._ and have fun studying scalaz (and perhaps category theory, too). Let me know how it goes. There’s the series learning Scalaz if you need some further reading.
p.s. I’m on my way to learn what the concept of functor means to functional programmers. I’m yet to find it out.