Is &quot;Socket2 a b&quot; any different from the pair (a,b)?<div><br></div><div>Assuming Socket2 looks roughly like the following:</div><div><br></div><div>&gt; import Data.Monoid</div><div>&gt; data Socket2 a b = Socket2 (a,b)</div>
<div><br></div><div>Then if both a and b are instances of Monoid we can make Socket2 a b into an instance of Monoid the same way we make (a,b) into a Monoid.</div><div><br></div><div><br></div><div>&gt; instance (Monoid a, Monoid b) =&gt; Monoid (Socket a b) where</div>
<div>&gt;     mempty = Socket2 (mempty, mempty)</div><div>&gt;     <span style="background-color:rgb(255,255,255);font-family:arial,sans-serif;font-size:13px">Socket2 (a, b) `mappend` Socket2 (w, x) = Socket2 (a `mappend` w, b </span><span style="background-color:rgb(255,255,255);font-family:arial,sans-serif;font-size:13px">`mappend` x)</span></div>
<div><span style="background-color:rgb(255,255,255);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="background-color:rgb(255,255,255);font-family:arial,sans-serif;font-size:13px">You were only missing the restriction that both types a and b must be instances of Monoid in order to make Socket a b into an instance of Monoid.</span></div>
<div><span style="background-color:rgb(255,255,255);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="background-color:rgb(255,255,255);font-family:arial,sans-serif;font-size:13px"><br></span></div>
<div><br></div><div><font face="arial, sans-serif">Dan Feltey</font></div><div><span style="background-color:rgb(255,255,255);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="background-color:rgb(255,255,255);font-family:arial,sans-serif;font-size:13px"><br>
</span></div><div><br><div class="gmail_quote">On Thu, Dec 20, 2012 at 8:40 PM, Christopher Howard <span dir="ltr">&lt;<a href="mailto:christopher.howard@frigidcode.com" target="_blank">christopher.howard@frigidcode.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In my current pondering of the compose-able objects them, I was thinking<br>
it would be useful to have the follow abstractions: Monoids, which were<br>
themselves tuples of Monoids. The idea was something like so:<br>
<br>
code:<br>
--------<br>
import Data.Monoid<br>
<br>
instance Monoid (Socket2 a b) where<br>
<br>
  mempty = Socket2 (mempty, mempty)<br>
<br>
  Socket2 (a, b) `mappend` Socket2 (w, x) = Socket2 (a `mappend` w, b<br>
`mappend` x)<br>
<br>
data Socket2 a b = Socket2 (a, b)<br>
--------<br>
<br>
However, this does not compile because of errors like so:<br>
<br>
code:<br>
--------<br>
Sockets.hs:9:21:<br>
    No instance for (Monoid a)<br>
      arising from a use of `mempty&#39;<br>
    In the expression: mempty<br>
    In the first argument of `Socket2&#39;, namely `(mempty, mempty)&#39;<br>
    In the expression: Socket2 (mempty, mempty)<br>
--------<br>
<br>
This makes sense, but I haven&#39;t figured out a way to rewrite this to<br>
make it work. One approach I tried was to encode Monoid constraints into<br>
the data declaration (which I heard was a bad idea) but this didn&#39;t<br>
work, even using forall. Also I tried to encode it into the instance<br>
declaration, but the compiler kept complaining about errant or illegal<br>
syntax.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
<a href="http://frigidcode.com" target="_blank">frigidcode.com</a><br>
<br>
</font></span><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>