<div><div dir="auto">If you’re going to import Data.Semigroup as a sort of backwards compatibility shim, then I don’t think you should import it qualified. To avoid the ambiguity error, how about “import Data.Monoid hiding ((<>))”?</div><br><div class="gmail_quote"><div>On Mon, Apr 30, 2018 at 05:57 Joey Hess <<a href="mailto:id@joeyh.name">id@joeyh.name</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I tried to follow the instructions at <br>
<a href="https://prime.haskell.org/wiki/Libraries/Proposals/SemigroupMonoid" rel="noreferrer" target="_blank">https://prime.haskell.org/wiki/Libraries/Proposals/SemigroupMonoid</a><br>
and I got a <<loop>> when my code runs with ghc 8.2.2.<br>
<br>
My code looked like this:<br>
<br>
import Data.Monoid<br>
import Prelude<br>
<br>
data InfoVal v = NoInfoVal | InfoVal v<br>
deriving (Show)<br>
<br>
instance Monoid (InfoVal v) where<br>
mempty = NoInfoVal<br>
mappend _ v@(InfoVal _) = v<br>
mappend v NoInfoVal = v<br>
<br>
Following the "recommended variant" for compatible code, I changed that<br>
too:<br>
<br>
{-# LANGUAGE CPP #-}<br>
<br>
import Data.Monoid<br>
import qualified Data.Semigroup as Sem<br>
import Prelude<br>
<br>
data InfoVal v = NoInfoVal | InfoVal v<br>
deriving (Show)<br>
<br>
instance Monoid (InfoVal v) where<br>
mempty = NoInfoVal<br>
#if !(MIN_VERSION_base(4,11,0))<br>
mappend = (<>)<br>
#endif<br>
<br>
instance Sem.Semigroup (InfoVal v) where<br>
_ <> v@(InfoVal _) = v<br>
v <> NoInfoVal = v<br>
<br>
This loops because <> comes from Data.Monoid not from Data.Semigroup, <br>
so mappend = mappend.<br>
<br>
Note that I diverged slightly from the instructions to get to this wrong<br>
code; I imported Data.Semigroup qualified. Without the qualification,<br>
the above code fails to compile, with Ambiguous occurrence ‘<>’<br>
<br>
So, the transition instructions don't produce code that ghc 8.2.2 can build, <br>
and when the obvious fix is made to get it to compile, it compiles into a<br>
loop, that is *not* a loop when compiled with newer versions of ghc.<br>
<br>
-- <br>
see shy jo<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">-- Dan Burton</div>