gpt4 book ai didi

scala - EitherT[选项,A,B] ===选项[Either[A,B]]

转载 作者:行者123 更新时间:2023-12-02 06:57:05 26 4
gpt4 key购买 nike

如果我理解正确,EitherT[Option,A,B] 应该与 Option[Either[A,B]] 相同,但编译器不同意.以下代码编译失败:

def f[A,B] = implicitly[EitherT[Option, A, B] === Option[Either[A,B]]] 

我错过了什么?

最佳答案

它们是同构的,但不是同一个值。 EitherT[Option,A,B] 包装类型 Option[Either[A,B]] 的值以提供不同的行为。让我们看一下定义:

final case class EitherT[F[_], A, B](run: F[A \/ B])

所以 EitherT 包装了一个 Option,名为 run 的值是 Option[Either[A,B]]

关于scala - EitherT[选项,A,B] ===选项[Either[A,B]],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29160167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com