可能重复:
C# - 方法签名中的新关键字
假设我有3个班:GrandDad,爸爸,儿子.儿子继承自祖父,继承自祖父.
每个类都实现了foo.
// GrandDad class:
public virtual void foo()
// Dad class:
new public virtual void foo()
// Son class:
public override void foo()
Run Code Online (Sandbox Code Playgroud)
我不明白为什么爸爸会使用新关键字的原因.据我所知,使用新隐藏方法.你为什么想做这个?
我阅读了新的MSDN解释,但讨论只是机械的,而不是架构的.
谢谢
我的理解是我可以调用Array.prototype.slice.call(arguments, 1)返回数组的尾部.
为什么这段代码不会返回[2,3,4,5]?
function foo() {
return Array.prototype.slice.call(arguments,1);
}
alert(foo([1,2,3,4,5]));
Run Code Online (Sandbox Code Playgroud) 运行我的sbt构建,我得到以下未解决的依赖项.
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.typesafe.play#sbt-link;2.2.0: not found
[warn] :: com.typesafe.play#play-exceptions;2.2.0: not found
[warn] :: com.typesafe.play#routes-compiler_2.10;2.2.0: not found
[warn] :: com.typesafe.play#templates-compiler_2.10;2.2.0: not found
[warn] :: com.typesafe.play#console_2.10;2.2.0: not found
[warn] :: net.contentobjects.jnotify#jnotify;0.94: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
Run Code Online (Sandbox Code Playgroud)
我的项目结构如下所示:
parent
|
--> sbtApp1
--> playApp
--> sbtApp2
--> project
--> Build.scala
--> plugins.sbt
--> build.sbt
Run Code Online (Sandbox Code Playgroud)
我的父/ project/plugins.sbt具有以下内容:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")
我将以下行添加到parent/build.sbt,但我仍然遇到编译时失败.
libraryDependencies += "play" % "play_2.10" % "2.1.0"
constJavaScript中的关键字是否创建了对不可变数据结构的不可变引用?[我假设JavaScript中存在不可变数据结构.]
因为string它似乎这样做:
var x = "asdf";
const constantX = x;
alert("before mutation: " + constantX);
x = "mutated"
alert("after mutation: " + constantX);
Run Code Online (Sandbox Code Playgroud)
输出:
突变之前:asdf
突变后:asdf
我DelayedInit在Scala深度看 ...
评论是我对代码的理解.
以下特征接受单个参数,该参数是非严格评估的(由于=>),并返回Unit.它的行为类似于构造函数.
trait DelayedInit {
def delayedInit(x: => Unit): Unit
}
Run Code Online (Sandbox Code Playgroud)
据我所知App,这个特性有一个var x等于0-arity(无参数)的函数.x根据对delayedInit方法的调用来分配.
然后,main将调用apply '_()'上x如果有一个Some(Function0[Unit])类型.如果x是None,那么什么都不会发生.
trait App extends DelayedInit {
var x: Option[Function0[Unit]] = None
override def delayedInit(cons: => Unit) {
x = Some(() => cons)
}
def main(args: Array[String]): Unit =
x.foreach(_())
}
Run Code Online (Sandbox Code Playgroud)
然后,按照本书的例子,我去了REPL:
scala> val x = new App …Run Code Online (Sandbox Code Playgroud) 给定父和子类.
scala> class Parent
defined class Parent
scala> class Child extends Parent
defined class Child
Run Code Online (Sandbox Code Playgroud)
定义父母和子女的含义
scala> implicit val a = new Parent
a: Parent = Parent@5902f207
scala> implicit val b = new Child
b: Child = Child@3f7d8bac
Run Code Online (Sandbox Code Playgroud)
使用implicitly找出其中隐含的得到解决.
scala> implicitly[Child]
res1: Child = Child@3f7d8bac
Run Code Online (Sandbox Code Playgroud)
我理解的例证:
Parent
|
Child -- implicit resolution gets the most specific, lowest sub-type
Run Code Online (Sandbox Code Playgroud)
现在,让我们使用逆变型.
scala> trait A[-T]
defined trait A
scala> case class Concrete[T]() extends A[T]
defined class Concrete
Run Code Online (Sandbox Code Playgroud)
然后定义Parent和Child类.
scala> class Parent …Run Code Online (Sandbox Code Playgroud) 了解一个Haskell礼物Error:
instance (Error e) => Monad (Either e) where
return x = Right x
Right x >>= f = f x
Left err >>= f = Left err
fail msg = Left (strMsg msg)
Run Code Online (Sandbox Code Playgroud)
Hackage礼物Either:
data Either a b = Left a | Right b
Run Code Online (Sandbox Code Playgroud)
如果我理解正确,那么ErrorMonad Either就是它的a类型.此外,它看起来像是fail处理异常.
但是,我也看到也有Control.Monad.Either- http://hackage.haskell.org/package/category-extras-0.53.4/docs/Control-Monad-Either.html.
为什么会Control.Monad.Error被选中Control.Monad.Either,反之亦然?
在REPL中,我写出了Reflection - TypeTags和Manifests中的例子.
我WeakTypeTag和之间的区别感到困惑TypeTag.
scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._
Run Code Online (Sandbox Code Playgroud)
TypeTag
scala> def paramInfo[T](x: T)(implicit tag: TypeTag[T]): Unit = {
| val targs = tag.tpe match { case TypeRef(_, _, args) => args }
| println(s"type tag of $x has type arguments $targs")
| }
paramInfo: [T](x: T)(implicit tag: reflect.runtime.universe.TypeTag[T])Unit
Run Code Online (Sandbox Code Playgroud)
WeakTypeTag
scala> def weakParamInfo[T](x: T)(implicit tag: WeakTypeTag[T]): Unit = {
| val targs = tag.tpe match { case TypeRef(_, _, args) => args }
| …Run Code Online (Sandbox Code Playgroud) 鉴于以下内容:
的src/main /斯卡拉/网/ Equals5.scala
package net
import scala.language.experimental.macros
import scala.reflect.macros.Context
case class Equals5(value: Int) {
require(value == 5)
}
object Equals5 {
implicit def wrapInt(n: Int): Equals5 = macro verifyIntEquals5
def verifyIntEquals5(c: Context)(n: c.Expr[Int]): c.Expr[Equals5] = {
import c.universe._
val tree = n.tree match {
case Literal(Constant(x: Int)) if x == 5 =>
q"_root_.net.Equals5($n)"
case Literal(Constant(x: Int)) =>
c.abort(c.enclosingPosition, s"$x != 0")
case _ =>
q"_root_.net.Equals5($n)"
}
c.Expr(tree)
}
}
Run Code Online (Sandbox Code Playgroud)
build.sbt
val paradiseVersion = "2.1.0-M5"
scalaVersion := "2.11.7"
libraryDependencies += …Run Code Online (Sandbox Code Playgroud) 鉴于以下fp课程:
class Functor f where
(<$>) ::
(a -> b)
-> f a
-> f b
class Functor f => Extend f where
(<<=) ::
(f a -> b)
-> f a
-> f b
Run Code Online (Sandbox Code Playgroud)
我定义<$$>如下:
(<$$>) ::
Comonad f =>
(a -> b)
-> f a
-> f b
(<$$>) f fa = f <$> fa
Run Code Online (Sandbox Code Playgroud)
但是,我很想知道是否有其他方法可以在<$$>不使用的情况下实现<$>.在那儿?如果是这样,请出示!
scala ×4
haskell ×2
javascript ×2
architecture ×1
c# ×1
comonad ×1
immutability ×1
new-operator ×1
sbt ×1