5

It looks like scalaz provides a Functor instance for List but does not provide it for Array (or 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 ?

Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

7

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?

wheaties
  • 35,646
  • 15
  • 94
  • 131
  • 1
    Why is `Functor` required to be immutable ? Which laws does the mutability break ? – Michael Aug 01 '16 at 17:29
  • @Michael no laws requires immutability. The spirit of what is trying to be achieved and the direction the people behind Scalaz would like others to go requires immutability. – wheaties Aug 01 '16 at 18:03
  • got it, thank you. I should probably use `ImmutableArray`. – Michael Aug 01 '16 at 18:06