假设我有两种类型IntResult和StringResult: import cats._
import cats.data._
import cats.implicits._
scala> case class MyError(msg: String)
defined class MyError
scala> type Result[A] = Either[NonEmptyList
我们知道fmap是fmap :: Functor f => (a -> b) -> f a -> f b和sum是sum :: (Num a, Foldable t) => t a -> a,但下面的代码混淆了我。 > :t (fmap sum Just)
(fmap sum Just) :: Num b => b -> b
> fmap sum Just 3
3
为什么?
我已阅读下列问题: Template functors vs functions C++ Functors - and their uses C++ function template partial specialization? 我明白C++ functors是良好的。但我不能推断,如果将执行以下操作会发生什么: template <typename T, unsigned int state
的确如此: λ :i Applicative
class Functor f => Applicative (f :: * -> *) where
同时: fmap f x = pure f <*> x
- 由Applicative规律,我们可以从pure & <*>定义fmap。 我不明白为什么我要我要一个Applicative如果,真的,fmap可以自动在pure和<*>规定设立每次