If you add a third pattern, you can see exactly what it&#39;s failing to match:<br><br>&nbsp;&nbsp;&nbsp; kmerge x = error (show x)<br><br>In order to do this, you just need to add Show constraints for a and b in the type of kmerge:<br><br>
&nbsp;&nbsp; kmerge :: (Show a, Show b, Eq a) =&gt; [(a,[b])]-&gt;[(a,[b])]<br>
<br>You&#39;ll find that the pattern that it&#39;s failing to match is:<br><br>&nbsp;&nbsp; [(&#39;b&#39;,[5,4]),(&#39;b&#39;,[1]),(&#39;b&#39;,[6])]<br><br>Because you combined 5 and 4 and passed that on to your recursive &#39;kmerge&#39; call.&nbsp; Your patterns only cover the case where there is exactly one element in the list.
<br><br>- Phil<br><br><div class="gmail_quote">On Dec 6, 2007 9:39 AM, georg86 &lt;<a href="mailto:georg_straube@web.de">georg_straube@web.de</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>Hello!<br>I need to write a function which should is supposed to merge multiple<br>entries with the same<br>key (out of a sorted key-value-list) into one single entry.<br>However, I keep getting a pattern matching error.
<br><br>(For example, for input [(&#39;b&#39;,[5]),(&#39;b&#39;,[4]),(&#39;b&#39;,[1]),(&#39;b&#39;,[6])]:<br>&quot;Program error: pattern match failure: kgroup<br>[(&#39;b&#39;,[5,4]),(&#39;b&#39;,[1]),(&#39;b&#39;,[6])]&quot;)
<br><br>Thank you very much for your help.<br><br>kmerge::Eq a =&gt; [(a,[b])]-&gt;[(a,[b])]<br><br>kmerge [] = []<br><br>kmerge ((x,[y]):[]) = [(x,[y])]<br><br>kmerge ((x,[y]):(u,[v]):xs) | x == u = kmerge ((x,[y,v]):xs)
<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | otherwise = (x,[y]):(u,[v]):kmerge xs<br><font color="#888888">--<br>View this message in context: <a href="http://www.nabble.com/Pattern-matching-error-tf4957268.html#a14196413" target="_blank">
http://www.nabble.com/Pattern-matching-error-tf4957268.html#a14196413</a><br>Sent from the Haskell - Haskell-Cafe mailing list archive at <a href="http://Nabble.com" target="_blank">Nabble.com</a>.<br><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></font></blockquote></div><br>