Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Jakub Kozłowski
@kubukoz
I would guess that's just withSnakeCaseMemberNames but maybe not
I see Travis said the same thing :P
you should write tests for your usecase anyways, so you can see if that's enough
Conner Bryan
@cab

r.e. recursion schemes -- I'm creating the corresponding NodeF[A] for my Node type, but what's the right way to generalize something like

sealed trait Node
final case class Name(value: String) extends Node
sealed trait Expression extends Node
final case class Block(name: Name, exprs: List[Expression]) extends Node

where I want to keep the more narrow type for some values? because I currently have

sealed trait NodeF[A]
final case class NameF(value: String) extends NodeF[A]
sealed trait ExpressionF[A] extends NodeF[A]
final case class BlockF[A](name: A, exprs: List[A]) extends NodeF[A]
Conner Bryan
@cab
or do I have to give up that subtyping?
Conner Bryan
@cab
hmm, or does that subtyping not even matter for the generalized type
elyphas
@elyphas
Q
Rakesh
@rakeshkr00
I am encountering
FieldsValidation.scala:45: value mapN is not a member of (FieldsValidation.this.ValidationResult[Boolean], FieldsValidation.this.ValidationResult[Boolean])
[error]         checkPoints(in.geom) map { y => (res,y).mapN(FieldValidationResult)}
[error]
and the code I have is
case class FieldValidationResult(inLandMass:Boolean, gt4Points: Boolean)

sealed trait FieldsValidation  {
  type ValidationResult[A] = ValidatedNel[FieldException, A]

  def validateGeom(in: Loc360FieldsAvro)(implicit system: ActorSystem, db: Database ): Future[ValidationResult[FieldValidationResult]] = {

    def checkPoints(wkt: String): Future[ValidationResult[Boolean]] = {
      val geom: Geometry = new WKTReader().read(in.geom)
      geom.setSRID(4326)
      Future {
        if (geom.getNumPoints > 4) true.validNel else LessThanFourVerticesError.invalidNel
      }
    }

    def checkIfWithinLandmass(wkt: String): Future[ValidationResult[Boolean]] = {
      db.run(checkIfGeometryWithinLandMass(wkt)) map { x => {
        if (!x) false.validNel else GeometryFallOutsideOfLandAreaError.invalidNel
      }
      }
    }

    checkIfWithinLandmass(in.geom) flatMap {
      res => {
        checkPoints(in.geom) map { y => (res,y).mapN(FieldValidationResult)}
      }
    }

  }
}

object FieldsValidation extends FieldsValidation
what has gone wrong here?
Rob Norris
@tpolecat
Are you compiling with -Ypartial-unification? If so then what are your imports?
Rakesh
@rakeshkr00
.
Apart from application specific imports, other relevant ones are :
import akka.actor.ActorSystem
import cats.data.Validated._
import cats.data._
import cats.implicits._
import cats.syntax.apply._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
Rob Norris
@tpolecat
Remove the import for cats.syntax.apply
If you import cats.implicits, which you should, you don’t need (and in fact cannot use) the fine-grained imports for instances and syntax.
Rakesh
@rakeshkr00
Now my app can compile without that error. Thanks @tpolecat
Rob Norris
@tpolecat
Cool.
Jakub Kozłowski
@kubukoz
I'm trying to implement Eq for Cofree using the definition in https://hackage.haskell.org/package/free-4.1/docs/Control-Comonad-Cofree.html - so far one wall I hit is a diverging implicit... since I don't see Cats depending on shapeless, do we have a different mechanism of coping with these than Lazy?
(Eq (f (Cofree f a)), Eq a) => Eq (Cofree f a)
translated to Scala that's implicit def catsFreeEqForCofree[S[_], A : Eq](implicit S: Eq[S[Cofree[S, A]]]): Eq[Cofree[S, A]]
I have a workaround, but it requires Foldable and Applicative for S[_]
instead of Eq - and it's basically eqv x y = x.head == y.tail && (x.tail, y.tail).product.forall { case (a, b) => eqv(a, b) }
any better ideas?
funny thing is, it's divering for S = List but works fine for Option
Jakub Kozłowski
@kubukoz
if only this was possible: implicit def catsFreeEqForCofree[S[_], A : Eq](implicit S: Eq[Cofree[S, A]] => Eq[S[Cofree[S, A]]])
with implicit function types, who knows...
Jakub Kozłowski
@kubukoz
trait Eq[A]
trait X[A]

implicit val forXOfA: implicit Eq[Int] => Eq[X[Int]] = null
implicitly[implicit Eq[Int] => Eq[X[Int]]]
nope, still doesn't compile (implicit not found)
Alexander Konovalov
@alexknvl
you need quantified contexts
Jakub Kozłowski
@kubukoz
please enlighten me
basically haskell?
or this
Jakub Kozłowski
@kubukoz
looks like it
wonder if there's a mechanism already used in cats
Alexander Konovalov
@alexknvl
I doubt it.
considering there is no Forall
Jakub Kozłowski
@kubukoz
ohh
so with that in mind
implicit def forListOfA[A](implicit A: Eq[A]): Eq[List[A]] = ???
//here!
implicitly[implicit Eq[Int] => Eq[List[Int]]]
would it be the first or the second line that needed e.g. forall?
to me it looks like valid scala
it might even work if A: Eq[A] in the first line isn't marked implicit
aaaand the implicit keyword disappears in the second line
but that's just an implicit view then
Rob Norris
@tpolecat
@kubukoz you might look at how these are defined in matryoshka
Jakub Kozłowski
@kubukoz

so my reasoning for this working in dotty is that:
given

implicit def forList[A](A: Eq[A]): Eq[List[A]] = ???
implicitly[Eq[Int] => Eq[List[Int]]]

compiles in scala, then

implicit def forList[A]: implicit Eq[A] => Eq[List[A]] = ???
implicitly[implicit Eq[Int] => Eq[List[Int]]]

should also compile

@tpolecat I'll take a look (later), thanks
EqualT?
I was thinking about sth like trait EqK[F[_]] { def eqv[A](x: F[A], y: F[A]): Boolean } before