Haskell语言学习笔记(71)Semigroup

Semigroup

class Semigroup a where
        (<>) :: a -> a -> a
        sconcat :: NonEmpty a -> a
        stimes :: Integral b => b -> a -> a

class Semigroup a => Monoid a where
        mempty  :: a

        mappend :: a -> a -> a
        mappend = (<>)

        mconcat :: [a] -> a
        mconcat = foldr mappend mempty

半群(Semigroup)是个类型类,它是幺半群(Monoid)的基类。

猜你喜欢

转载自www.cnblogs.com/zwvista/p/8966941.html