Domanda

Possible Duplicate:
Good scalaz introduction

I would like to learn more about Scalaz, possibly using Scalaz7 to be avoid rewiring my brain once it is declared stable. My problem is that Scalaz contains a lot of functionality. While most of it is meant to be independent of other parts, I would like to have a bird's eye view of the global funcitonality offered by Scalaz and how it is organized. As far as I know, Scalaz offers, among other things,

  • Functor, Applicative and Monad traits,
  • new monads such as Validation (edit: turns out it is only an applicative)
  • monad transformers (OptionT, EitherT....)
  • Itereatees
  • Lenses
  • Zippers

Added to this there are a lot of implicit conversions, and new constructors such as some which overlap with the standard library but behave better with regards to types

:type Some(3) // Some[Int]
:type some(3) // Option[Int]

I have a basic grasp of most of these constructions, but I am not fluent with any of the concepts.

Do you have any suggestion in what order to learn the library, what logical dependencies exist between modules? More generally, where can I find a high level overview of the library?

EDIT It seems that most answers are directed towards learning the basic components of functional programming, like monads, so I will try to be more precise. I have a basic knowledge of Haskell and a mathematician background, so my issue is not related to category theory or basic functional programming.

My problem is that Scalaz is a huge library. I do not know what to find where, what methods are available or useful on various data types. What I really need is a map that, for instance, will tell me that when I want to iterate over resources that need to be disposed, I may want to consider iteratees and what kind of operations I can do with that. More like a panoramic of the functionality available with the library.

È stato utile?

Soluzione

I would recommend the excellent series Learning scalaz by Eugene Yokota on Scalaz 7. The author follows the structure of Learn You a Haskell for Great Good. The approach is systematic and very pedagogic.

Altri suggerimenti

My advice would be not to wait until you feel like you have a high-level understanding of the library—just pick a couple of tools to start with and then follow conceptual links as you go.

Validation (which by the way isn't actually a monad) is probably the single best place to start. If you've ever used Either for validation in the standard library, Validation will feel both familiar and much more convenient. You'll find lots of useful discussions of Validation both here on StackOverflow and elsewhere.

Once you're comfortable working with Validation you should have a good basic understanding of the applicative functor type class, which is useful in many other contexts.

Monoid is another good starting point. It's a very simple type class (essentially just an associative addition-like operation and an identity element), and once you understand it you'll see monoids everywhere. See for example this answer (full disclosure: it's by me) showing how to use monoids to solve a problem that might not initially look very monoidy.

There are lots of other handy little tools in Scalaz that you can use without needing to grasp the entire big picture. Bifunctor is one of my favorites—it makes working with tuples much more convenient by giving you a way to map a function over either side:

scala> import scalaz._, Scalaz._
import scalaz._
import Scalaz._

scala> def inc(i: Int) = i + 1
inc: (i: Int)Int

scala> def repeat(n: Int)(s: String) = s * n
repeat: (n: Int)(s: String)String

scala> (inc(_)) <-: (1, "a") :-> repeat(3)
res0: (Int, String) = (2,aaa)

Once you have a good working understanding of a few of these concepts, I'd suggest Brent Yorgey's Typeclassopedia, which is Haskell-oriented but does a fantastic job of giving you just enough category theory and abstract algebra to understand most of the stuff you'll find in Scalaz.

Some of the videos I found useful:

Most of these have great slides, if you are hardcore then read them without the video.

Also learn to read Haskell type signatures and browse the Haskell typeclassopedia.

While I would never turn anyone away from the Haskell tutorials, they can be a bit mind-boggling if you're an OOP-style developer and aren't familiar with why you'd ever want to live in a functional world.

I gave a talk called "scalaz For the Rest of Us" which approaches scalaz though examples that everyone is familiar with: memoization (Memo in scalaz), domain validation (Validation in scalaz), etc. That way the "use case" is clear and can start learning how to solve the familiar problems using the power of scalaz.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top