Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在基类中定义了scalaz零_Scala_Types_Scalaz - Fatal编程技术网

在基类中定义了scalaz零

在基类中定义了scalaz零,scala,types,scalaz,Scala,Types,Scalaz,我刚开始学Scalaz。我试图为我的类型在其超类中定义一个零 class Base { implicit def BaseZ: Zero[this.type] = zero(classOf[this.type].newInstance() ) } class Child extends Base ~Option(null:Child) //trying to make this produce: new Child 我有两个错误: 1) 按原样,这会产生“错误:需要类类型,但找到Ba

我刚开始学Scalaz。我试图为我的类型在其超类中定义一个零

class Base { 
  implicit def BaseZ: Zero[this.type] = zero(classOf[this.type].newInstance() )
}

class Child extends Base

~Option(null:Child) //trying to make this produce: new Child
我有两个错误:

1) 按原样,这会产生“错误:需要类类型,但找到Base.this.type”

2) 如果我将this.type的第二个匹配项更改为Base(这没有用),则

类型失配
找到:基
必需:Base.this.type


有人能帮我弄清楚这是怎么回事吗?在这里输入?我真的不想将类型参数传递或重写到Base。

此。类型与此类的类型不同
this.type
是此特定实例的单例类型。换言之,以下措施将不起作用:

scala> class X { def x:this.type=new X }
<console>:7: error: type mismatch;
 found   : X
 required: X.this.type
       class X { def x:this.type=new X }

对于零,我将创建一个伴生对象,并将每个零放在其中。

因此,没有办法说扩展基的每个子对象的零应该生成一个新的子对象吗?
scala> class X { def x:this.type=this }
defined class X