Свой Monoid

Anonymous
haskell
01/26/2023 12:11 PM
408 B
26
Indexable
newtype Maybe' a = Maybe' { getMaybe :: Maybe a }
    deriving (Eq,Show)

instance Monoid a => Monoid (Maybe' a) where
    mempty = Maybe' (Just mempty)
    Maybe' Nothing `mappend` m = m
    m `mappend` Maybe' Nothing = m
    Maybe' (Just m1) `mappend` Maybe' (Just m2) = Maybe' (Just (m1 `mappend` m2))
Editor is loading...