I'm having a look at 20 Intermediate Scala Exercises and am having some difficulty with exercise 4. Unfortunately I can't find any solutions posted anywhere and I'm wondering if it's actually solvable.
Fluffy is clearly a thinly disguised Functor and furry is fmap.
trait Fluffy[F[_]] {
def furry[A, B](f: A => B, fa: F[A]): F[B]
}
object Fluffy {
// Exercise 1
// Relative Difficulty: 1
def ListFluffy: Fluffy[List] = new Fluffy[List] {
def furry[A, B](f: A => B, fa: List[A]): List[B] = fa map f
// am assuming this is the right idea...
}
// Exercise 4
// Relative Difficulty: 1
def ArrayFluffy: Fluffy[Array] = new Fluffy[Array] {
def furry[A, B](f: A => B, fa: Array[A]): Array[B] = ???
}
The problem is that I can't create an Array[B] without a context bound B: ClassManifest, but if I add one it breaks the contract with the Fluffy trait.
Since these questions are from 2008, presumbably before the days of Manifest, is the only option in Scala 2.9 to ignore the exercises involving arrays, or is there some other way that I'm overlooking?
According to this it's not solvable since scala 2.8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With