说我有一个功能
function1 :: (MonadError String m, MonadIO m) => m Int
function2 :: (MonadError Int m, MonadIO m) => m Int
Run Code Online (Sandbox Code Playgroud)
和一个函数来转换Int为String
renderException :: Int -> String
Run Code Online (Sandbox Code Playgroud)
有没有办法实现function3,即重用所有3个功能?
function3 :: (MonadError String m, MonadIO m) => m Int
-- add the results from function1, function2 and
-- transform function2 error into a String
Run Code Online (Sandbox Code Playgroud) 我有一个 SBT 项目,我将它发布到 Sonatype 没有问题,我将其转换为多模块 SBT 项目。现在我想:
将包含所有聚合子模块的 jar/javadoc/sources/pom 文件发布到 Sonatype(意味着它们应该使用 sbt-pgp 插件进行签名)
也将每个单独的子模块发布到 Sonatype
我尝试为此使用sbt 程序集插件,但没有成功。您是否有一个示例 Build.scala 文件,它可以显示实现此目的的最佳结构是什么?
我正在使用带有Scala 2.10.2(运行Java 1.7.0_51)构建的play 2.2.1的Specs2.我一直在阅读有关如何使用Specs2进行设置/拆卸的内容.我看过使用"After"特征的例子如下:
class Specs2Play extends org.specs2.mutable.Specification {
"this is the first example" in new SetupAndTeardownPasswordAccount {
println("testing")
}
}
trait SetupAndTeardownPasswordAccount extends org.specs2.mutable.After {
println("setup")
def after = println("teardown ")
}
Run Code Online (Sandbox Code Playgroud)
这很好,除了我的所有测试都使用"在新的WithApplication中".看来我需要的是一个既是"WithApplication"又是"After"的对象.下面不编译,但基本上是我想要的:
trait SetupAndTeardownPasswordAccount extends org.specs2.mutable.After with WithApplication
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是,如何在已经使用"InApplication"的测试中添加setup/teardown?我主要担心的是我们所有的测试都使用了这样的伪路由(所以他们需要With Application).
val aFakeRequest = FakeRequest(method, url).withHeaders(headers).withBody(jsonBody)
val Some(result) = play.api.test.Helpers.route(aFakeRequest)
result
Run Code Online (Sandbox Code Playgroud) 这是我想要做的简化示例.假设您有一HList对:
let hlist = HCons (1, "1") (HCons ("0", 2) (HCons ("0", 1.5) HNil))
Run Code Online (Sandbox Code Playgroud)
现在我想编写一个函数replaceAll,它将用相同类型的第一个"值"替换给定类型的所有"键".例如,有了HList上面的内容,我想替换所有的String键,"1"它是第一个String找到的类型的值HList
replaceAll @String hlist =
HCons (1, "1") (HCons ("1", 2) (HCons ("1", 1.5) HNil))
Run Code Online (Sandbox Code Playgroud)
这似乎需要路径依赖类型,以便"提取"第一对的类型,并能够在第二步中使用它来指导键的替换,但我不知道如何在Haskell中对此进行编码.
我有以下设计问题:
/**
* Those 2 traits are the public API
*/
trait Box {
def include(t: Token): Box
}
trait Token
/**
* Implementation classes
*/
case class BoxImpl(id: Int) extends Box {
/**
* the implementation of this method depends on the implementation
* of the Token trait
* TODO: REMOVE asInstanceOf
*/
def include(t: Token) = BoxImpl(t.asInstanceOf[TokenImpl].id + id)
}
case class TokenImpl(id: Int) extends Token
// use case
val b: Box = new BoxImpl(3)
val o: Token …Run Code Online (Sandbox Code Playgroud)