I came up with some code when trying to understand applicatives:<div><br></div><div><div>import Control.Applicative</div><div>import qualified Data.Map as M</div><div><br></div><div>instance Applicative (M.Map String) where</div>

<div>  pure x = M.fromList [(&quot;&quot;,x)]</div><div>  fs &lt;*&gt; xs = M.fromList [(k1 ++ &quot; &quot; ++ k2,v1 v2) | k1 &lt;- M.keys fs, k2 &lt;- M.keys xs, v1 &lt;- M.elems fs, v2 &lt;- M.elems xs]</div></div><div>

<br></div><div>1. When I :load this in ghci it gives me some error about using (M.Map String) here, and tells me it&#39;ll work if I use the -XFlexibleInstances flag. Why is this type of behavior disabled by default? Is it potentially dangerous in some way?</div>

<div><br></div><div>2. When running the following:</div><div><br></div><div>       fromList [(&quot;double&quot;,(*2))] &lt;*&gt; fromList[(&quot;two&quot;,2),(&quot;seven&quot;,7)]</div><div><br></div><div>I get:</div><div>

<br></div><div>        fromList [(&quot;double seven&quot;,4),(&quot;double two&quot;,4)]</div><div><br></div><div>instead of what I&#39;d expect:</div><div><br></div><div>        fromList [(&quot;double seven&quot;,14),(&quot;double two&quot;,4)]</div>

<div><br></div><div>Although this:</div><div><br></div><div><div>        (*2) &lt;$&gt; fromList[(&quot;two&quot;,2),(&quot;seven&quot;,7)]</div><div><br></div><div>gives what I&#39;d expect:</div><div><br></div><div>        fromList [(&quot;seven&quot;,14),(&quot;two&quot;,4)]</div>

</div><div><br></div><div>Why is this happening? I can&#39;t seem to figure it out.</div><div><br></div><div><br></div>