- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Is Array still a covariant functor?
Sun, 2009-11-29, 04:04
Can this trait be implemented for Array for 2.8.0?
trait Functor[F[_]] {
def fmap[A, B](a: F[A], f: A => B): F[B]
}
object Functor {
def ArrayFunctor = new Functor[Array] {
def fmap[A, B](a: Array[A], f: A => B) = {
// error: could not find implicit value for evidence parameter
of type scala.reflect.ClassManifest[B]
// a map f toArray
error("Can this be done?")
}
}
}
Sun, 2009-11-29, 04:47
#2
Re: Is Array still a covariant functor?
Thanks David, I will implement accordingly.
David Hall wrote:
> On Sat, Nov 28, 2009 at 7:04 PM, Tony Morris wrote:
>
>> Can this trait be implemented for Array for 2.8.0?
>>
>> trait Functor[F[_]] {
>> def fmap[A, B](a: F[A], f: A => B): F[B]
>> }
>>
>> object Functor {
>> def ArrayFunctor = new Functor[Array] {
>> def fmap[A, B](a: Array[A], f: A => B) = {
>> // error: could not find implicit value for evidence parameter
>> of type scala.reflect.ClassManifest[B]
>> // a map f toArray
>>
>> error("Can this be done?")
>> }
>> }
>> }
>>
>
> I believe the answer is no. You need to say B:ClassManifest (which
> breaks the interface) or you can use GenericArray
>
> http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/...
>










On Sat, Nov 28, 2009 at 7:04 PM, Tony Morris wrote:
> Can this trait be implemented for Array for 2.8.0?
>
> trait Functor[F[_]] {
> def fmap[A, B](a: F[A], f: A => B): F[B]
> }
>
> object Functor {
> def ArrayFunctor = new Functor[Array] {
> def fmap[A, B](a: Array[A], f: A => B) = {
> // error: could not find implicit value for evidence parameter
> of type scala.reflect.ClassManifest[B]
> // a map f toArray
>
> error("Can this be done?")
> }
> }
> }
I believe the answer is no. You need to say B:ClassManifest (which
breaks the interface) or you can use GenericArray
http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/...