scalaz

Turning A => M[B] into M[A => B]

£可爱£侵袭症+ 提交于 2019-11-28 07:10:53
For a monad M , Is it possible to turn A => M[B] into M[A => B] ? I've tried following the types to no avail, which makes me think it's not possible, but I thought I'd ask anyway. Also, searching Hoogle for a -> m b -> m (a -> b) didn't return anything, so I'm not holding out much luck. chi In Practice No, it can not be done, at least not in a meaningful way. Consider this Haskell code action :: Int -> IO String action n = print n >> getLine This takes n first, prints it (IO performed here), then reads a line from the user. Assume we had an hypothetical transform :: (a -> IO b) -> IO (a -> b)

Good scalaz introduction [closed]

心已入冬 提交于 2019-11-28 02:30:54
Recently scalaz caught my eye. It looks very interesting, but I have not found any good introduction to the library. Seems that scalaz incorporates a lot of ideas from haskell and mathematics. Most articles that I found assume that you already feel comfortable with these concepts. What I'm looking for is gradual introduction to the library and underlying concepts - from simple and basic concepts to more advanced (which basesd in basics). I also looked to the examples , but it's hard for me to find the point where I should start to learn library. Can somebody recommend me some good scalaz

Why is List a Semigroup but Seq is not?

余生长醉 提交于 2019-11-27 20:29:30
I'm fairly new to scalaz and I am trying to figure out why the following code works: import scalaz._ import Scalaz._ scala> Map[String,List[String]]() |+| Map[String,List[String]]() res3: scala.collection.immutable.Map[String,List[String]] = Map() but this doesn't... import scalaz._ import Scalaz._ scala> Map[String,Seq[String]]() |+| Map[String,Seq[String]]() <console>:14: error: value |+| is not a member of scala.collection.immutable.Map[String,Seq[String]] Map[String,Seq[String]]() |+| Map[String,Seq[String]]() I see the Map implicit for Semigroup, but I don't see the one for List or Seq.

Different Scala Actor Implementations Overview

瘦欲@ 提交于 2019-11-27 19:45:59
问题 I'm trying to find the 'right' actor implementation. I realized there is a bunch of them and it's a bit confusing to pick one. Personally I'm especially interested in remote actors, but I guess a complete overview would be helpful to many others. This is a pretty general question, so feel free to answer just for the implementation you know about. I know about the following Scala Actor implementations (SAI). Please add the missing ones. Scala 2.7 (difference to) Scala 2.8 Akka (http://www

why isn't Validation a Monad? (scalaz7)

南笙酒味 提交于 2019-11-27 19:04:02
an example use case: def div2(i: Int): Validation[String, Int] = if (i%2 == 0) Validation.success(i/2) else Validation.failure("odd") def div4(i: Int) = for { a <- div2(i) b <- div2(a) } yield b error : Unable to unapply type scalaz.Validation[String,Int] into a type constructor of kind M[_] that is classified by the type class scalaz.Bind I guess the error is caused by the compiler can't find a Monad instance for Validation[String, Int] I can make one for myself, like: object Instances { implicit def validationMonad[E] = new Monad[({type L[A] = Validation[E, A]})#L] { override def point[A](a:

Scalaz Bind[Seq] typeclass

馋奶兔 提交于 2019-11-27 15:17:45
I'm currently porting some code from traditional Scala to Scalaz style. It's fairly common through most of my code to use the Seq trait in my exposed API signatures rather than a concrete type (i.e. List, Vector) directly. However, this poses some problem with Scalaz, since it doesn't provide an implementation of a Bind[Seq] typeclass. i.e. This will work correctly. List(1,2,3,4) >>= bindOperation But this will not Seq(1,2,3,4) >>= bindOperation failing with the error could not find implicit value for parameter F0: scalaz.Bind[Seq] I assume this is an intentional design decision in Scalaz -

Converting a tuple of options to an option of tuple with Scalaz or Shapeless

青春壹個敷衍的年華 提交于 2019-11-27 14:40:51
问题 Having (Some(1), Some(2)) I expect to get Some((1, 2)) and having (Some(1), None) I expect to get None 回答1: You can use the fact that Scalaz 7 provides a Bitraverse instance for tuples and then sequence as usual (but with bisequence instead of sequence ): scala> import scalaz._, std.option._, std.tuple._, syntax.bitraverse._ import scalaz._ import std.option._ import std.tuple._ import syntax.bitraverse._ scala> val p: (Option[Int], Option[String]) = (Some(1), Some("a")) p: (Option[Int],

Using context bounds “negatively” to ensure type class instance is absent from scope

天涯浪子 提交于 2019-11-27 13:16:45
tl;dr : How do I do something like the made up code below: def notFunctor[M[_] : Not[Functor]](m: M[_]) = s"$m is not a functor" The ' Not[Functor] ', being the made up part here. I want it to succeed when the 'm' provided is not a Functor, and fail the compiler otherwise. Solved : skip the rest of the question and go right ahead to the answer below. What I'm trying to accomplish is, roughly speaking, "negative evidence". Pseudo code would look something like so: // type class for obtaining serialization size in bytes. trait SizeOf[A] { def sizeOf(a: A): Long } // type class specialized for

Validation versus disjunction

雨燕双飞 提交于 2019-11-27 11:43:17
Suppose I want to write a method with the following signature: def parse(input: List[(String, String)]): ValidationNel[Throwable, List[(Int, Int)]] For each pair of strings in the input, it needs to verify that both members can be parsed as integers and that the first is smaller than the second. It then needs to return the integers, accumulating any errors that turn up. First I'll define an error type: import scalaz._, Scalaz._ case class InvalidSizes(x: Int, y: Int) extends Exception( s"Error: $x is not smaller than $y!" ) Now I can implement my method as follows: def checkParses(p: (String,

Scalaz state monad examples

♀尐吖头ヾ 提交于 2019-11-27 10:13:26
I haven't seen many examples of the scalaz state monad. There is this example but it is hard to understand and there is only one other question on stack overflow it seems. I'm going to post a few examples I've played with but I would welcome additional ones. Also if somebody can provide example on why init , modify , put and gets are used for that would be great. Edit: here is an awesome 2 hours presentation on the state monad. I assume, scalaz 7.0.x and the following imports (look at answer history for scalaz 6.x ): import scalaz._ import Scalaz._ The state type is defined as State[S, A]