简体   繁体   English

为什么Scalaz中没有Array的Functor实例

[英]Why is there no Functor instance for Array in Scalaz

It looks like scalaz provides a Functor instance for List but does not provide it for Array (or Seq ). 看起来scalazList提供了Functor实例,但是没有为Array (或Seq )提供它。

scala> val fa = Functor[Array]
<console>:17: error: could not find implicit value for parameter F: scalaz.Functor[Array]
       val fa = Functor[Array]
                       ^
scala> val fl = Functor[List]
fl: scalaz.Functor[List] = scalaz.std.ListInstances$$anon$1@20c4b59

scala> val fl = Functor[Seq]
<console>:17: error: could not find implicit value for parameter F: scalaz.Functor[Seq]
       val fl = Functor[Seq]
                       ^

Why is that ? 这是为什么 ? Aren't they functors ? 他们不是算子吗?

Scalaz requires that objects follow the laws for Functor s. Scalaz要求对象遵循Functor的定律。 It also prescribes to the "everything immutable" philosophy of code construction. 它还规定了代码构造的“一切不可变”的哲学。 That said, Array is mutable, so they wouldn't create a Functor instance for it. 也就是说, Array是可变的,所以他们不会为它创建一个Functor实例。 Seq on the other hand is an abstract interface and it is unknown what the "correct" data type will be. 另一方面, Seq是一个抽象接口,不知道“正确”的数据类型是什么。 That is, for Seq how to know which underlying object to return and therefore not violate any laws? 也就是说,对于Seq如何知道要返回哪个底层对象,因此不违反任何法律?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM