~scompall/opaque-types-to-infinity/trunk

« back to all changes in this revision

Viewing changes to opaque-types-to-infinity.org

  • Committer: Stephen Compall
  • Date: 2018-05-13 17:45:37 UTC
  • Revision ID: scompall@nocandysw.com-20180513174537-kdgcrr0wcxinlb08
Derive substCo instead

Show diffs side-by-side

added added

removed removed

Lines of Context:
216
216
** Subtyping is incompatible with disagreeing instances
217
217
Or, makes those instances *incoherent*.
218
218
#+BEGIN_SRC scala
 
219
import scalaz.syntax.semigroup._, scalaz.std.string._
219
220
val h = Instance("hello")
220
221
val w = Instance("world")
221
222
 
222
 
scala> import scalaz.syntax.semigroup._, scalaz.std.string._
223
223
scala> h |+| w: String
224
224
res2: String = worldhello
225
225
 
251
251
sealed abstract class LabelModule {
252
252
  type Label
253
253
 
254
 
  def substCo[F[_]: Functor](fl: F[Label]): F[String]
 
254
  def substCo[F[_]: Functor](fl: F[Label]): F[String] = {
 
255
    type K[A] = F[A] => F[String]
 
256
    implicit val K =
 
257
      Contravariant[? => F[String]].icompose[F]
 
258
    substContra[K](identity).apply(fl)
 
259
  }
255
260
 
256
261
  def substContra[F[_]: Contravariant](fs: F[String])
257
 
      : F[Label] = {
258
 
    type K[A] = F[A] => F[Label]
259
 
    implicit val K = Contravariant[? => F[Label]].compose[F]
260
 
    substCo[K](identity).apply(fs)
261
 
  }
 
262
                                         : F[Label]
262
263
}
263
264
#+END_SRC
264
265
* Infinite types