I'm looking at http://hseeberger.wordpress.com/2010/11/25/introduction-to-category-theory-in-scala/ and there's a bit of code that I can't understand how it works:
object Functor {
def fmap[A, B, F[_]](as: F[A])(f: A => B)(implicit functor: Functor[F]): F[B] =
functor.fmap(as)(f)
implicit object ListFunctor extends Functor[List] {
def fmap[A, B](f: A => B): List[A] => List[B] =
as => as map f
}
}
Specifically, how is ListFunctor.fmap accessing as when the definition of as is in the scope of Functor.fmap and (as far as I can tell) inaccessible to ListFunctor.fmap?
(related with a twist) There's a previous iteration to the above code that's defined:
trait Functor[F[_]] extends GenericFunctor[Function, Function, F] {
final def fmap[A, B](as: F[A])(f: A => B): F[B] =
fmap(f)(as)
}
object ListFunctor extends Functor[List] {
def fmap[A, B](f: A => B): List[A] => List[B] = as => as map f
}
But again, as seems to be magically accessible to ListFunctor. I guess if I understand one of these, I'll understand the other.