Created
July 14, 2016 06:26
-
-
Save benhutchison/fc2794ded1ca1b15ad07f30813b290ee to your computer and use it in GitHub Desktop.
Any simpler way to write Refined Higher-kinded types?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?