Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Any simpler way to write Refined Higher-kinded types?
Welcome to the Ammonite Repl 0.6.2
(Scala 2.11.8 Java 1.8.0_51)
@ load.plugin.ivy("org.spire-math" %% "kind-projector" % "0.8.0")
@ load.ivy("org.typelevel" %% "cats" % "0.6.0")
@ import cats._; import implicits._
import cats._;
import implicits._
@ load.ivy("eu.timepit" %% "refined" % "0.5.0")
@ import eu.timepit.refined._; import api._; import collection._
import eu.timepit.refined._;
import api._;
import collection._
@ implicit def nonEmptyReducible[F[_]](implicit F: Foldable[F]): Reducible[F Refined NonEmpty] =
new NonEmptyReducible[F Refined NonEmpty, F] {
override def split[A](fa: F[A] Refined NonEmpty) = ???
}
cmd5.scala:1: eu.timepit.refined.api.Refined[F,eu.timepit.refined.collection.NonEmpty] takes no type parameters, expected: one
implicit def nonEmptyReducible[F[_]](implicit F: Foldable[F]): Reducible[F Refined NonEmpty] =
^
cmd5.scala:2: eu.timepit.refined.api.Refined[F,eu.timepit.refined.collection.NonEmpty] takes no type parameters, expected: one
new NonEmptyReducible[F Refined NonEmpty, F] {
^
Compilation Failed
@ implicit def nonEmptyReducible[F[_]](implicit F: Foldable[F]): Reducible[F[?] Refined NonEmpty] =
new NonEmptyReducible[F[?] Refined NonEmpty, F] {
override def split[A](fa: F[A] Refined NonEmpty) = ???
}
cmd5.scala:1: eu.timepit.refined.api.Refined[[α$0$]F[α$0$],eu.timepit.refined.collection.NonEmpty] takes no type parameters, expected: one
implicit def nonEmptyReducible[F[_]](implicit F: Foldable[F]): Reducible[F[?] Refined NonEmpty] =
^
cmd5.scala:2: eu.timepit.refined.api.Refined[[α$1$]F[α$1$],eu.timepit.refined.collection.NonEmpty] takes no type parameters, expected: one
new NonEmptyReducible[F[?] Refined NonEmpty, F] {
^
Compilation Failed
@ implicit def nonEmptyReducible[F[_]](implicit F: Foldable[F]): Reducible[Lambda[X => F[X] Refined NonEmpty]] =
new NonEmptyReducible[Lambda[X => F[X] Refined NonEmpty], F] {
override def split[A](fa: F[A] Refined NonEmpty) = ???
}
defined function nonEmptyReducible
@
@benhutchison

This comment has been minimized.

Copy link
Owner Author

commented Jul 14, 2016

Hopefully, the goal is apparent here: provide a Reducible instance (a cats typeclass for folding over non-empty collection) , for a Foldable collection if it has been certified as non-empty.

The problem this gist illustrates is the difficulty of writing partially-applied, nested higher kinded types. Is there any simpler way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.