Michael Michael - 10 months ago 75
Scala Question

Why is there no Functor instance for Array in Scalaz

It looks like

provides a
instance for
but does not provide it for

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 Functors. 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. Seq on the other hand is an abstract interface and it is unknown what the "correct" data type will be. That is, for Seq how to know which underlying object to return and therefore not violate any laws?