From 9400e3a3ee6f3b33a5eefe2f563ba92e9a8e24a4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 14 Mar 2016 22:51:54 -0400 Subject: [PATCH] `coalesce` operates within an Alternative functor. --- test/Data/Adjoined/Spec.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/Data/Adjoined/Spec.hs b/test/Data/Adjoined/Spec.hs index bd2a1da23..3ce8b726a 100644 --- a/test/Data/Adjoined/Spec.hs +++ b/test/Data/Adjoined/Spec.hs @@ -1,5 +1,6 @@ module Data.Adjoined.Spec (spec) where +import Control.Applicative import Data.Adjoined import Data.Coalescent import Data.Typeable @@ -43,7 +44,7 @@ instance Arbitrary a => Arbitrary (Uncoalesced a) where arbitrary = Uncoalesced <$> arbitrary instance Coalescent (Uncoalesced a) where - coalesce _ _ = Nothing + coalesce a b = pure a <|> pure b -- | A wrapper which always coalesces values. @@ -54,7 +55,7 @@ instance Arbitrary a => Arbitrary (Coalesced a) where arbitrary = Coalesced <$> arbitrary instance Monoid a => Coalescent (Coalesced a) where - coalesce a b = Just (Coalesced (runCoalesced a `mappend` runCoalesced b)) + coalesce a b = pure (Coalesced (runCoalesced a `mappend` runCoalesced b)) -- | A wrapper which coalesces asymmetrically. @@ -67,8 +68,8 @@ instance Arbitrary a => Arbitrary (Semicoalesced a) where arbitrary = Semicoalesced <$> arbitrary instance Monoid a => Coalescent (Semicoalesced a) where - Semicoalesced (True, a) `coalesce` Semicoalesced (flag, b) = Just (Semicoalesced (flag, a `mappend` b)) - Semicoalesced (False, _) `coalesce` _ = Nothing + Semicoalesced (True, a) `coalesce` Semicoalesced (flag, b) = pure (Semicoalesced (flag, a `mappend` b)) + a `coalesce` b = pure a <|> pure b -- | Returns a string with the name of a type.