1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 15:35:14 +03:00

Add a Monoid instance for Adjoined over partial semigroups.

This commit is contained in:
Rob Rix 2016-03-04 22:25:27 -05:00
parent 42579d9c5b
commit d54324e20c

View File

@ -1,6 +1,8 @@
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
module Data.Adjoined where
import Control.Monad
newtype Adjoined a = Adjoined { unAdjoined :: Maybe a }
deriving (Eq, Foldable, Functor, Show, Traversable)
@ -17,3 +19,7 @@ instance Applicative Adjoined where
instance Monad Adjoined where
return = pure
Adjoined a >>= f = Adjoined $ a >>= unAdjoined . f
instance PartialSemigroup a => Monoid (Adjoined a) where
mempty = Adjoined Nothing
mappend (Adjoined a) (Adjoined b) = Adjoined . join $ coalesce <$> a <*> b