我试图通过移植Dan Piponi本教程中的一些例子来了解Scala中的Monad Transformers:http: //blog.sigfpe.com/2006/05/grok-haskell-monad-transformers.html
我做了几件简单的事:
import Control.Monad.State
import Control.Monad.Identity
test1 = do
a <- get
modify (+1)
b <- get
return (a,b)
test2 = do
a <- get
modify (++"1")
b <- get
return (a,b)
go1 = evalState test1 0
go2 = evalState test2 "0"
Run Code Online (Sandbox Code Playgroud)
变为:
import scalaz._, Scalaz._
val test1 = for {
a <- get[Int]
_ <- modify[Int](1+)
b <- get
} yield (a,b)
val test2 = for {
a <- get[String]
_ <- modify[String](_ + …
Run Code Online (Sandbox Code Playgroud) [error] test.scala:31: ambiguous implicit values:
[error] both method taggedQueryParamDecoder in trait ExternalInstances0 of type [A, T](implicit evidence$2: org.http4s.QueryParamDecoder[A])org.http4s.QueryParamDecoder[scalaz.@@[A,T]]
[error] and method iiQueryParamDecoder in trait ExternalInstances1 of type [B](implicit ii: foo.InvariantInstances[B])org.http4s.QueryParamDecoder[B]
[error] match expected type org.http4s.QueryParamDecoder[scalaz.@@[String,foo.tags.Social]]
[error] implicitly[QueryParamDecoder[String @@ Social]]
[error] ^
Run Code Online (Sandbox Code Playgroud)
我导入instances._
; instances
延伸ExternalInstances1
和ExternalInstances1
延伸ExternalInstances0
.由于这种继承,我希望其ExternalInstances1
成员能够赢得胜利ExternalInstances0
,而不是产生歧义.
为什么会发生这种情况,我该如何解决?谢谢.
来源位于http://scastie.org/12233,转载如下:
/***
scalaVersion := "2.11.7"
libraryDependencies += "org.http4s" %% "http4s-core" % "0.10.0"
resolvers ++= Seq(
"tpolecat" at "http://dl.bintray.com/tpolecat/maven",
"Scalaz Bintray Repo" …
Run Code Online (Sandbox Code Playgroud) 我的印象是有人在那里使用Scalaz编写纯应用程序,但基于这个例子:[ 在scalaz中堆叠StateT ],看起来任何真实的东西也是不可能的毛茸茸的.
在Scala中是否有任何关于真实,模块化,松散耦合的纯应用程序的指南或示例?我期待这意味着scalaz.effect.SafeApp
和RWST相比IO,但我想听听已经完成它的人们的意见.
谢谢.
编辑:在没有答案的情况下,我开始收集资源作为下面的答案.如果您有任何贡献的示例或相关链接,请执行.
在这个似乎涉及xsbt-web-plugin的奇怪案例中,我得到了错误
unresolved dependency: play#play-json_2.10;2.2-SNAPSHOT: not found
加载server
子项目时.依赖项和正确的解析程序在library
子项目中指定,具体server
取决于.如果我不包含webSettings
在服务器中,它不会爆炸,但我试图在那里建立一个.war.
[根] /project/Build.scala
import sbt._
import Keys._
object MyBuild extends Build {
lazy val root = Project("root", base = file(".")).aggregate(library,server)
lazy val library = Project(id = "library", base = file("library"))
lazy val server = Project(id = "server", base = file("server")).dependsOn(library)
}
Run Code Online (Sandbox Code Playgroud)
[根] /project/plugins.sbt
// p.s. why do I need this here instead of [root]/server/project/plugins.sbt?
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "0.3.0")
Run Code Online (Sandbox Code Playgroud)
[根] /library/build.sbt
scalaVersion := "2.10.1"
libraryDependencies += …
Run Code Online (Sandbox Code Playgroud)