小编srp*_*ish的帖子

F#集合初始化器语法

F#中的集合初始化程序语法是什么?在C#中,您可以编写如下内容:

new Dictionary<string, int>() {
    {"One", 1},
    {"two", 2}}
Run Code Online (Sandbox Code Playgroud)

我如何在F#中做同样的事情?我想我可以使用自己的语法,但似乎应该有一个内置或标准的语法.

f# inline

34
推荐指数
4
解决办法
9753
查看次数

为什么Scala为涉及Either和值定义的'for'表达式选择"Product"类型

如果我使用Option创建一个带有值定义的for comprehension,它将按预期工作:

scala> for (a <- Some(4); b <- Some(5); val p = a * b) yield p
res0: Option[Int] = Some(20)
Run Code Online (Sandbox Code Playgroud)

如果我没有值定义,则使用Either做同样的事情:

scala> for (a <- Right(4).right; b <- Right(5).right) yield a * b
res1: Either[Nothing,Int] = Right(20)
Run Code Online (Sandbox Code Playgroud)

但是如果我使用了值定义,scala似乎推断了for comprehension的错误容器类型:

scala> for (a <- Right(4).right; b <- Right(5).right; val p = a * b) yield p
<console>:8: error: value map is not a member of Product with Serializable with Either[Nothing,(Int, Int)]
for (a <- Right(4).right; b <- Right(5).right; val …
Run Code Online (Sandbox Code Playgroud)

scala type-inference for-comprehension

14
推荐指数
1
解决办法
6039
查看次数

如何为eclipse设置Super/Windows/mod4键绑定

我想在eclipse(3.7.2)中设置一些涉及键("windows"键)的键绑定,但是当我按下它时它似乎没有拿起那个修饰键.为什么?我能做什么才能检测到它?

eclipse linux keyboard-events windows-key xmodmap

11
推荐指数
1
解决办法
1310
查看次数

可堆叠特征模式可以与单例对象一起使用吗?

我想使用可堆叠的特征模式与单例对象,但我似乎无法找到如何使编译器快乐:

abstract class Pr {
  def pr()
}

trait PrePostPr extends Pr {
  abstract override def pr() {
    println("prepr")
    super.pr()
    println("postpr")
  }
}

object Foo extends Pr with PrePostPr {
  def pr() = println("Foo")
}
Run Code Online (Sandbox Code Playgroud)

尝试在repl中对此进行评估会产生以下错误:

<console>:10: error: overriding method pr in trait PrePostPr of type ()Unit;
 method pr needs `override' modifier
         def pr() = println("Foo")
Run Code Online (Sandbox Code Playgroud)

singleton scala traits

8
推荐指数
1
解决办法
546
查看次数