Haskell 中的 Free 实现是:
data Free f a =
Pure a
| Free (f (Free f a))
而Scalaz中的实现是:
sealed abstract class Free[S[_], A]
private case class Return[S[_], A](a: A) extends Free[S, A]
private case class Suspend[S[_], A](a: S[A]) extends Free[S, A]
private case class Gosub[S[_], B, C](a: Free[S, C], f: C => Free[S, B]) extends Free[S, B]
为什么 scalaz 实现不类似于 Haskell,例如:
sealed trait Free[F[_],A]
case class Return[F[_],A](a: A) extends Free[F,A]
case class GoSub[F[_],A](s: F[Free[F,A]]) extends Free[F,A]
这两个实现是同构的吗?