Compilation problems using scalaz MA methods for Set but not list

The following are compiled simply using the scala beta and scalaz 5.0 snapshot:

val p1: Int => Boolean = (i : Int) => i > 4

val s: List[Int] = List(1, 2, 3)
val b1 = s βˆƒ p1

      

And yet it is not:

val s: Set[Int] = Set(1, 2, 3)
val b1 = s βˆƒ p1

      

I am getting the following error:

Found: Int => Boolean
Required: Boolean => Boolean

Method signature βˆƒ

:

def βˆƒ(p: A => Boolean)(implicit r: FoldRight[M]): Boolean = any(p)

      

And the scope must be implicit SetFoldRight

. Similarly, for the methods: βˆ€

, βˆ‹

and ∈:

- what is happening?

+2


a source to share


2 answers


It seems that A

in MA[M[_],A]

there Boolean

for a Set

. The following implicit exists in the object Scalaz

:

implicit def Function1ApplyMA[A, R](f: A => R): MA[PartialApply1Of2[Function1, A]#Apply, R] = ma[PartialApply1Of2[Function1, A]#Apply, R](f)

      

Now I don't quite understand what is going on with the types here, but it looks like A

in MA[M[_],A]

is the return type Function1

. Set[A]

extends A => Boolean

, so why A

is the definition βˆƒ

inferred to Boolean

.



One fix is ​​to use an explicit method ma

to convert a Set to ma

, rather than have the implications do the heavy lifting:

val s = ma(Set(1, 2, 3))

      

+3


a source


I need to add this to object Scalaz

:

implicit def SetMA[M[_] <: Set[_], A](s: M[A]): MA[M, A] = ma[M, A](s)

      

But, thanks to # 2741 , I ran into an issue that makes this a higher priority than the offending conversion:

implicit def Function1ApplyMA[A, R](f: A => R): MA[PartialApply1Of2[Function1, A]#Apply, R]  = ma[PartialApply1Of2[Function1, A]#Apply, R](f)

      



I am very sorry that Seq

both are Set

implicitly converted to Function1

and not inherited from it.

UPDATE

It is now fixed .

+3


a source







All Articles