斯卡拉的佛罗里达 - 盒子去香蕉少

时间:2014-06-02 08:03:44

标签: scala higher-kinded-types

请参阅https://www.fpcomplete.com/user/edwardk/phoas

一些背景代码

trait ProfunctorStr[->[_, _]] {
 def dimap[A, B, C, D]: (C => A) => (B => D) => (A -> B) => (C -> D) = { f =>
    g => {
      lazy val h: (A -> B) => (C -> B) = mapfst(f)
      lazy val hh: (C -> B) => (C -> D) = mapsnd(g)
      h andThen hh
   }
  }

  def mapfst[A, B, C]: (C => A) => (A -> B) => (C -> B) =
    f => p => dimap[A, B, C, B](f)(x => x)(p)

  def mapsnd[A, B, C]: (B => C) => (A -> B) => (A -> C) =
    f => p => dimap[A, B, A, C](x => x)(f)(p)

  // convenient for certain implementations
  def mfst[A, B, C](p: A -> B)(f: C => A): C -> B = mapfst(f)(p)

  def msnd[A, B, C](p: A -> B)(f: B => C): (A -> C) = mapsnd(f)(p)

 }


abstract class Rec[F[_, _], A, B] {
  def runRec[R]: (B => R) => (F[A, R] => R) => R
}

object Rec {
  abstract class RecProfunctor[F[_, _]](implicit F: ProfunctorStr[F]) 
    extends ProfunctorStr[({type l[x, y] = Rec[F, x, y] })#l] {
      def dimap[A, B, C, D] = { f =>
       g => rab =>
        def P = function1Profunctor
        new Rec[F, C, D] {
          def runRec[R] = { ??? }
      }
    }
  }
}

阅读那篇文章我觉得我得到了要点,但我在scala中实现时遇到了麻烦,特别是如何转换Rec [F,C,D] {runRec [R] = {?!?!?!如果你能解释如何转换那个

,我真的很想得到这个
 (B => R) => (F[A, R] => R) => R

 (D => R) => (F[C, R] => R) => R

我想...... 任何方式任何和所有帮助非常感谢,细节深受喜爱。谢谢

0 个答案:

没有答案