Functor
We have seen how map is defined for []
, and we can also map on other types. We call these types Functor
if they can be map
ped and can satistify the Functor
law at the same time.
Functor laws: map id = id | map (compose g f) = map g . map f
class Functor f where
map :: forall a b. (a -> b) -> f a -> f b
instance Functor Maybe where
map f (Just x) = Just (f x)
map f Nothing = Nothing
当前内容版权归 hamler-lang 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 hamler-lang .