我试图理解Monads made difficult中的说明,但是我很难弄清楚以下newtype定义:
newtype (FComp g f) x = FComp { unCompose :: g (f x) }
instance (Functor b c f, Functor a b g) => Functor a c (FComp g f) where
fmap f (FComp xs) = FComp $ fmap (fmap f) xs
我从未见过一种用括号中的表达式代替类型声明来解释 newtype 的方法。因此,我无法理解 fmap 函数定义的含义。 我也不明白为什么要定义 unCompose 字段但从未使用。我感觉我缺少一些 newtype 的基本语义。