我的理解是我可以调用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"
给定父和子类.
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) 我希望以下内容GetArgs.hs打印出传递给它的参数.
import System.Environment
main = do
args <- getArgs
print args
Run Code Online (Sandbox Code Playgroud)
但是,加载后ghci,我收到以下错误:
ghci> main 3 4 3
<interactive>:39:1:
Couldn't match expected type `a0 -> a1 -> a2 -> t0'
with actual type `IO ()'
The function `main' is applied to three arguments,
but its type `IO ()' has none
In the expression: main 3 4 3
In an equation for `it': it = main 3 4 3
Run Code Online (Sandbox Code Playgroud)
既然print有这种类型:
ghci>:t print print ::显示=> a - …
我正在关注foldM以获得如何使用它的直觉.
foldM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a
在这个简单的例子中,我简单地回来了[Just 100].但是,如果我想使用该b怎么办?
ghci> foldM (\a _ -> return a) (Just 100) [1,2,3] :: [Maybe Int]
[Just 100]
Run Code Online (Sandbox Code Playgroud)
我很困惑如何使用b内部(a -> b -> m a).
请帮助我获得这个功能的直觉以及如何使用b.
鉴于以下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)
但是,我很想知道是否有其他方法可以在<$$>不使用的情况下实现<$>.在那儿?如果是这样,请出示!
在下面的代码中,为什么会s1.printVal导致悬空指针错误?是不是s1直到它的销毁的对象,即它的指针,仍然可以访问?
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << "The value is " << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << "Say i am in someFunc " << endl;
}
int main()
{
Sample s1 = 10;
SomeFunc(s1);
s1.PrintVal(); // dangling pointer
}
Run Code Online (Sandbox Code Playgroud)
我跑了mvn checkstyle:checkstyle,但它没有使用我的自定义checkstyle XML文件.
请告诉我如何使用我自己的checkstyle文件,而不是默认/其中配置的任何一个?
在AngularJS中移动,我在// ERROR下面的行中收到JavaScript错误.
我为什么要这样Cannot set property 'show' of undefined?
<html ng-app>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js">
</script>
<div ng-controller='DeathrayMenuController'>
<button ng-click='toggleMenu()'>Toggle Menu</button>
<ul ng-show='menuState.show'>
<li ng-click='stun()'>Stun</li>
<li ng-click='disintegrate()'>Disintegrate</li>
<li ng-click='erase()'>Erase from history</li>
</ul>
<div/>
<script>
function DeathrayMenuController($scope) {
$scope.menuState.show = false; // ERROR HERE
$scope.toggleMenu = function() {
$scope.menuState.show = !$scope.menuState.show;
};
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我正在为Java类创建Reads并Writes使用Play Framework的JSON库.
我的一个类有一个抽象类字段.
ConcreteObj.java
public class ConcreteObj {
private AbstractObj someField;
public ConcreteObj(AbstractObj someField) {
this.someField = someField;
}
public AbstractObj getSomeField() { return this.someField };
Run Code Online (Sandbox Code Playgroud)
...
读写
implicit val ConcreteObjReads: Reads[ConcreteObj] =
(JsPath \ "someField").read[AbstractObj].map{x: AbstractObj => new ConcreteObj(x)}
implicit val ConcreteObjWrites: Writes[ConcreteObj] =
(JsPath \ "someField").write[AbstractObj].contramap{x: ConcreteObj => x.getField}
Run Code Online (Sandbox Code Playgroud)
然而,下一步,创建一个Reads[AbstractObj],对我来说没有意义,因为抽象类无法实例化.
我想这Writes[AbstractObj]看起来像:
implicit val AbstractObjWrites: Writes[AbstractObj] =
(JsPath \ "otherField").write[String].contramap{x: AbstractObj => x.getOtherField}
Run Code Online (Sandbox Code Playgroud)
但是Reads[AbstractObj]呢?