Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding my way through Scalaz [duplicate]

Tags:

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.

like image 974
Andrea Avatar asked Sep 12 '12 12:09

Andrea


2 Answers

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.

like image 162
paradigmatic Avatar answered Sep 20 '22 12:09

paradigmatic


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.

like image 29
Travis Brown Avatar answered Sep 19 '22 12:09

Travis Brown