diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2020-04-13 16:29:44 +0300 |
---|---|---|
committer | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2020-04-23 17:21:28 +0300 |
commit | e21f3023b095d9bbd000330b56aaaa2977134335 (patch) | |
tree | e4f66eb46539c3d62b47648297915d19d8105f6a /compiler/utils/Pretty.hs | |
parent | 8ea37b01b6ab16937f7b528b6bbae9fade9f1361 (diff) | |
download | haskell-wip/semigroup-sdoc.tar.gz |
Use Semigroup's (<>) for Doc/SDocwip/semigroup-sdoc
Before this patch, Outputable.hs defined its own (<>) which caused
conflicts with (Data.Semigroup.<>) and thus led to inconvenience.
However, replacing it is not trivial due to a different fixity:
http://www.haskell.org/pipermail/libraries/2011-November/017066.html
Nevertheless, it is possible to update the pretty-printing code to work
with (<>) of a different fixitiy, and that's what this patch implements.
Now Doc and SDoc are instances of Semigroup.
Diffstat (limited to 'compiler/utils/Pretty.hs')
-rw-r--r-- | compiler/utils/Pretty.hs | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/compiler/utils/Pretty.hs b/compiler/utils/Pretty.hs index 5adfdd7699..6e8686a62d 100644 --- a/compiler/utils/Pretty.hs +++ b/compiler/utils/Pretty.hs @@ -201,8 +201,7 @@ But it doesn't work, for if x=empty, we would have -- --------------------------------------------------------------------------- -- Operator fixity -infixl 6 <> -infixl 6 <+> +infixr 6 <+> -- matches that of (Semigroup.<>) infixl 5 $$, $+$ @@ -659,14 +658,10 @@ nilAboveNest g k q | not g && k > 0 -- No newline if no overlap -- --------------------------------------------------------------------------- -- Horizontal composition @<>@ --- We intentionally avoid Data.Monoid.(<>) here due to interactions of --- Data.Monoid.(<>) and (<+>). See --- http://www.haskell.org/pipermail/libraries/2011-November/017066.html - -- | Beside. -- '<>' is associative, with identity 'empty'. -(<>) :: Doc -> Doc -> Doc -p <> q = beside_ p False q +instance Semigroup Doc where + p <> q = beside_ p False q -- | Beside, separated by space, unless one of the arguments is 'empty'. -- '<+>' is associative, with identity 'empty'. |