1
1
mirror of https://github.com/github/semantic.git synced 2024-12-28 09:21:35 +03:00

Rewrite the Monoid instance using the uncons/unsnoc functions.

This commit is contained in:
Rob Rix 2016-03-11 18:43:28 -05:00
parent 115549407c
commit db103aea51

View File

@ -3,6 +3,7 @@ module Data.Adjoined where
import Control.Monad
import Data.Coalescent
import Data.Monoid
import Data.Sequence as Seq
-- | A collection of elements which can be adjoined onto other such collections associatively.
@ -32,7 +33,7 @@ instance Monad Adjoined where
instance Coalescent a => Monoid (Adjoined a) where
mempty = Adjoined mempty
Adjoined a `mappend` Adjoined b | as :> a' <- viewr a,
b' :< bs <- viewl b,
Just coalesced <- coalesce a' b' = Adjoined (as >< (coalesced <| bs))
| otherwise = Adjoined (a >< b)
a `mappend` b | Just (as, a') <- unsnoc a,
Just (b', bs) <- uncons b,
Just coalesced <- coalesce a' b' = as <> pure coalesced <> bs
| otherwise = Adjoined (unAdjoined a >< unAdjoined b)