Wednesday, 15 February 2012

scala - don't understand scalaz endo function -



scala - don't understand scalaz endo function -

in scalaz, endo function in function1ops implemented way:

def endo(implicit ev: r =:= t): endo[t] = endo.endo(t => ev(self(t)))

i curious why in body of endo.endo function, not taking self... endo.endo(self), behaves same endo.endo(t=> ev(self(t))).

here mimic implementation , see no difference between two. did miss something?

def endo[r, t](f: r => t)(implicit ev: t =:= r) = (x: r)=> ev(f(x)) def endo2[r, t](f: r => t)(implicit ev: t =:= r) = f

besides, doesn't first implementation add together overhead @ runtime?

the endo.endo function requires a => a. self value function t => r not comply endo requirement.

you in theory cast t => r t => t ev parameter created don't need cast , accidentally create error t => r not equal t => t.

they have written this:

def endo(implicit ev: r =:= t): endo[t] = endo.endo(self andthen ev)

your examples compile because returntype not set.

scala functional-programming implicit-conversion scalaz

No comments:

Post a Comment