summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-05-06 17:23:13 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-08-04 10:05:52 -0400
commit1b6e646e6edfdbb4e3b67509642bf9585a5da96c (patch)
treed253911187bce53eb557f293d5a5ea3ffff1eee0
parent9b719549fda563fb80b197fb47d9e508c7989d2d (diff)
downloadhaskell-1b6e646e6edfdbb4e3b67509642bf9585a5da96c.tar.gz
Make HsWrapper a Monoid
See instance documentation for caviat.
-rw-r--r--compiler/GHC/Tc/Types/Evidence.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/compiler/GHC/Tc/Types/Evidence.hs b/compiler/GHC/Tc/Types/Evidence.hs
index 7dd8dfef67..e260976c38 100644
--- a/compiler/GHC/Tc/Types/Evidence.hs
+++ b/compiler/GHC/Tc/Types/Evidence.hs
@@ -97,6 +97,8 @@ import Data.IORef( IORef )
import GHC.Types.Unique.Set
import GHC.Core.Multiplicity
+import qualified Data.Semigroup as S
+
{-
Note [TcCoercions]
~~~~~~~~~~~~~~~~~~
@@ -294,6 +296,25 @@ instance Data.Data HsWrapper where
dataTypeOf _ = hsWrapper_dataType
+-- | The Semigroup instance is a bit fishy, since @WpCompose@, as a data
+-- constructor, is "syntactic" and not associative. Concretely, if @a@, @b@,
+-- and @c@ aren't @WpHole@:
+--
+-- > (a <> b) <> c ?= a <> (b <> c)
+--
+-- ==>
+--
+-- > (a `WpCompose` b) `WpCompose` c /= @ a `WpCompose` (b `WpCompose` c)
+--
+-- However these two associations are are "semantically equal" in the sense
+-- that they produce equal functions when passed to
+-- @GHC.HsToCore.Binds.dsHsWrapper@.
+instance S.Semigroup HsWrapper where
+ (<>) = (<.>)
+
+instance Monoid HsWrapper where
+ mempty = WpHole
+
hsWrapper_dataType :: Data.DataType
hsWrapper_dataType
= Data.mkDataType "HsWrapper"