implicit def Function1Functor[R]: Functor[({type l[a]=(R) => a})#l] = new Functor[({type l[a]=(R) => a})#l] {
def fmap[A, B](r: R => A, f: A => B) = r andThen f
}
In the following code snippet, I define a Function1 Functor:implicit def Function1Functor[R]: Functor[({type l[a]=(R) => a})#l] = new Functor[({type l[a]=(R) => a})#l] { def fmap[A, B](r: R => A, f: A => B) = r andThen f }
1. But why is that signature ({type l[a]=(R) => a})#l like that? how to interpret that?
2. I could now randomly pick any type and qualify that as a Functor. For example.,
case class SomeRandomType[A] (param: A) // this does not know about the fact that it is going to be a Functor soonval someRandomTypeFunctor = new Functor[SomeRandomType] {def map[A, B](fa: SomeRandomType[A])(f: A => B): SomeRandomType[B] =SomeRandomType(f(fa.param))}So this to me is a Typeclass definition. Is that correct?
In the following code snippet, I define a Function1 Functor:implicit def Function1Functor[R]: Functor[({type l[a]=(R) => a})#l] = new Functor[({type l[a]=(R) => a})#l] { def fmap[A, B](r: R => A, f: A => B) = r andThen f }
1. But why is that signature ({type l[a]=(R) => a})#l like that? how to interpret that?
On 4/19/17 3:16 AM, Joe San wrote:
1. But why is that signature ({type l[a]=(R) => a})#l like that? how to interpret that?
type l[a]=(R) => a
l
l
type l[a]=(R) => a
2. I could now randomly pick any type and qualify that as a Functor.
For example.,case class SomeRandomType[A] (param: A) // this does not know about the fact that it is going to be a Functor soon
val someRandomTypeFunctor = new Functor[SomeRandomType] {def map[A, B](fa: SomeRandomType[A])(f: A => B): SomeRandomType[B] =SomeRandomType(f(fa.param))}So this to me is a Typeclass definition. Is that correct?