2012-06-21 3 views
1

내가 http://hseeberger.wordpress.com/2010/11/25/introduction-to-category-theory-in-scala/ 찾고 있어요 내가 어떻게 작동하는지 이해할 수없는 코드의 비트있다 : 특히스칼라 변수 범위는

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 
    } 
} 

, 어떻게 ListFunctor.fmapas에 액세스하는 것은 as의 정의는 경우 Functor.fmap의 범위에서 (내가 말할 수있는 한) ListFunctor.fmap에 액세스 할 수 없습니까? (트위스트 관련)

정의되어 위의 코드에 이전 반복 있습니다 :

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 
} 

그러나 다시는 asListFunctor에 마술 액세스 할 것으로 보인다. 나는이 중 하나를 이해한다면 다른 것을 이해할 것입니다.

답변

3

동일하지 않습니다. as, 두 개의 장소에서 우연히 같은 이름이 사용되었습니다. as => as map f은 함수 정의이고, 화살표 앞에있는 as은 바로이 함수의 매개 변수 선언입니다.

x => x map f으로 작성하면 완전히 동등합니다.

+0

아, 쏘지, 네 말이 맞아. 감사! – JasonMond