Finding my way through Scalaz [duplicate]
Asked Answered
B

4

23

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.

Became answered 12/9, 2012 at 12:4 Comment(2)
similar question: https://mcmap.net/q/125581/-good-scalaz-introduction-closedWildfowl
Just a remark: Validation is not a monad, just an Applicative Functor (in scalaz7 it doesn't even have flatMap)Sorcha
L
11

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.

Luker answered 12/9, 2012 at 13:12 Comment(6)
The series seems pretty basic, only covering standard monad stuff. I am looking for something that will give a more detailed overview of what I can find inside Scalaz. I have read Learn you a Haskell for great good, and it does not touch more advanced topics like lenses, Kiesli triples or itereatees, so I don't think the series will cover a significant part of the library.Became
I got through the book yesterday. I was thinking about covering topics like lenses and iteretees later. Send me comments or tweets to let me know what you want me to learn!Hourglass
@EugeneYokota I have trouble to find the correct imports with Scalaz 7 (except if I import everything). Could you add something about minimal imports ?Luker
@EugeneYokota Thank you for taking the time to comment here! I have no particular desire to have something covered; I was just worried because I had misunderstood the series and thought that it would end with the book, thereby leaving most of Scalaz unexplored.Became
By the way, as the days pass, this becomes more and more a great resource to dive into Scalaz!Became
Day 13 is dedicated to @Luker - eed3si9n.com/learning-scalaz-day13Hourglass
L
9

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.

Lymphangial answered 12/9, 2012 at 13:18 Comment(4)
I know pretty well cateogry theory and abstract algebra (I have a background as a researcher in algebraic geoemetry) so that is not my issue. I am also familiar with monads, functors and so on in the context of functional programming. My issue is more programming-related. For instance, say I want to learn about validation. Where do I import it? What methods will I have available? And so on. Of course I can read the sources or use inspection in the shell, but it would be useful to have something like a map of what is available where.Became
Sorry—your background wasn't clear from the question. In that case digging through the source is likely to be your best bet—there's not all that much of it and it's reasonably clear once you pick up a few of the conventions (type lambdas, implicit scope tricks, etc.). And of course there's example code in the project repo, plenty of blog posts, videos, etc.Lymphangial
Also I think the pick-a-place-to-start approach might still be appropriate (it's roughly how I started using Scalaz, and I also felt reasonably comfortable with the maths coming in).Lymphangial
Thank you, I have edited the question and upvoted the three answers I got so far anyway: they are good answers to a question that was not very precise!Became
S
6

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.

Sorcha answered 12/9, 2012 at 13:14 Comment(1)
I think the Practical Scalaz and Monoids are a fun and easy way to start.Sorcha
F
5

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.

Foretop answered 12/9, 2012 at 19:31 Comment(1)
Thank you for the slides. While I happen to know some functional programming, I found your examples useful to learn some bits of the Scalaz library :-)Became

© 2022 - 2024 — McMap. All rights reserved.