<div dir="ltr"><div>I have changed your code little bit, and now it works. <br></div><div><br></div><div>merge :: Ord a => [a] -> [a] -> [a]<br>merge [] second = second<br>merge first [] = first<br>merge first@(x:xs) second@(y:ys) <br> | x <= y = x : merge xs second<br> | otherwise = y : merge first ys</div><div><br></div><div>The reason your code is not working because<br></div><div><span class="gmail-m_201110480156966136inbox-inbox-s1"><font face="monospace">merge [4,5] []</font></span> is trying to match it against <font face="monospace">merge [x] [] = [x] </font>which expects one element list at first place so merge [1] [] would work<font face="monospace">,</font>but not merge (list having more than one element) [].</div><div><br></div><div>Best, <br></div><div>Mukesh Tiwari<br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 18, 2018 at 3:20 PM, trent shipley <span dir="ltr"><<a href="mailto:trent.shipley@gmail.com" target="_blank">trent.shipley@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<p class="m_201110480156966136inbox-inbox-p1">The below produces an error. And I am very proud that I could use the GHCi debugging tools to get this far.</p><p class="m_201110480156966136inbox-inbox-p1"><font face="monospace">merge [] []</font> works.</p><p class="m_201110480156966136inbox-inbox-p1"><font face="monospace">merge [1] [] </font>works.</p><p class="m_201110480156966136inbox-inbox-p1">I don't know why the failing example fails. It should return:</p><p class="m_201110480156966136inbox-inbox-p1"><font face="monospace">[4,5]</font></p><p class="m_201110480156966136inbox-inbox-p1">Help to unstuck is appreciated.</p><p class="m_201110480156966136inbox-inbox-p1"><span class="m_201110480156966136inbox-inbox-s1"><font face="monospace">:step merge [4,5] []</font></span></p>
<p class="m_201110480156966136inbox-inbox-p1"><span class="m_201110480156966136inbox-inbox-s1"><font face="monospace">*** Exception: ex6_8.hs:(12,1)-(16,66): Non-exhaustive patterns in function merge</font></span></p><p class="m_201110480156966136inbox-inbox-p1">Given:</p><p class="m_201110480156966136inbox-inbox-p1"><font face="monospace">merge :: Ord a => [a] -> [a] -> [a]</font></p><p class="m_201110480156966136inbox-inbox-p1"><font face="monospace">merge [] [] = []</font></p><p class="m_201110480156966136inbox-inbox-p1"><font face="monospace">merge [x] [] = [x]</font></p><p class="m_201110480156966136inbox-inbox-p1"><font face="monospace">merge [] [y] = [y]</font></p><p class="m_201110480156966136inbox-inbox-p1"><font face="monospace">merge first@(x:xs) second@(y:ys) | x <= y = x : merge xs second</font></p><p class="m_201110480156966136inbox-inbox-p1"><font face="monospace"> | otherwise = y : merge first ys</font></p><div><br></div></div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>