From 2a7adf2bdc6df0eb47028ae3e6d86033d9cb8de9 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Mon, 23 Apr 2018 10:46:26 +0300 Subject: [PATCH] Fix review comments --- src/Control/Monad/Validation.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Control/Monad/Validation.hs b/src/Control/Monad/Validation.hs index 9103f78..72c0659 100644 --- a/src/Control/Monad/Validation.hs +++ b/src/Control/Monad/Validation.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} @@ -48,14 +49,14 @@ instance (Ord k) => Ixed (MonoidMap k v) where instance (Ord k) => At (MonoidMap k v) where at key = _MonoidMap . at key +#if MIN_VERSION_base(4,11,0) instance (Ord k, S.Semigroup v) => S.Semigroup (MonoidMap k v) where - (MonoidMap a) <> (MonoidMap b) = - MonoidMap $ M.unionWith (S.<>) a b + (<>) = mmAppend +#endif instance (Ord k, Monoid v) => Monoid (MonoidMap k v) where mempty = MonoidMap M.empty - mappend (MonoidMap a) (MonoidMap b) = - MonoidMap $ M.unionWith (<>) a b + mappend = mmAppend instance (ToJSON k, ToJSON v) => ToJSON (MonoidMap k v) where toJSON (MonoidMap m) = toJSON $ L.map toObj $ M.toList m @@ -75,6 +76,14 @@ instance (Ord k, FromJSON k, FromJSON v) => FromJSON (MonoidMap k v) where val <- obj .: "value" return (key, val) +#if MIN_VERSION_base(4,11,0) +mmAppend :: (Ord k, S.Semigroup v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v +mmAppend (MonoidMap a) (MonoidMap b) = MonoidMap $ M.unionWith (S.<>) a b +#else +mmAppend :: (Ord k, Monoid v) => MonoidMap k v -> MonoidMap k v -> MonoidMap k v +mmAppend (MonoidMap a) (MonoidMap b) = MonoidMap $ M.unionWith (<>) a b +#endif + -- | Convenient for 'vZoom' as first artument. Will prevent generation -- of map with 'mempty' values mmSingleton :: (Eq v, Monoid v, Ord k) => k -> v -> MonoidMap k v