<div dir="ltr"><div><div>If you compile with -Wall, you get the following<br><br><span style="font-family:monospace">foo.hs:2:1: warning: [-Wincomplete-patterns]<br> Pattern match(es) are non-exhaustive<br> In an equation for ‘merge’:<br> Patterns not matched:<br> [] (_:_:_)<br> (_:_:_) []<br> |<br>2 | merge [] [] = []<br> | ^^^^^^^^^^^^^^^^...<br></span><br></div>That is to say, you never match if there is an empty list and a list of 2 or more.<br><br></div>Try this:<br><span style="font-family:monospace"><br>merge :: Ord a => [a] -> [a] -> [a]<br>merge [] ys = ys<br>merge xs [] = xs<br>merge first@(x:xs) second@(y:ys) | x <= y = x : merge xs second<br> | otherwise = y : merge first ys<br></span><br><div><div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 17, 2018 at 10:21 PM trent shipley <<a href="mailto:trent.shipley@gmail.com">trent.shipley@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<p class="m_3279232060946607623inbox-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_3279232060946607623inbox-inbox-p1"><font face="monospace">merge [] []</font> works.</p><p class="m_3279232060946607623inbox-inbox-p1"><font face="monospace">merge [1] [] </font>works.</p><p class="m_3279232060946607623inbox-inbox-p1">I don't know why the failing example fails. It should return:</p><p class="m_3279232060946607623inbox-inbox-p1"><font face="monospace">[4,5]</font></p><p class="m_3279232060946607623inbox-inbox-p1">Help to unstuck is appreciated.</p><p class="m_3279232060946607623inbox-inbox-p1"><span class="m_3279232060946607623inbox-inbox-s1"><font face="monospace">:step merge [4,5] []</font></span></p>
<p class="m_3279232060946607623inbox-inbox-p1"><span class="m_3279232060946607623inbox-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_3279232060946607623inbox-inbox-p1">Given:</p><p class="m_3279232060946607623inbox-inbox-p1"><font face="monospace">merge :: Ord a => [a] -> [a] -> [a]</font></p><p class="m_3279232060946607623inbox-inbox-p1"><font face="monospace">merge [] [] = []</font></p><p class="m_3279232060946607623inbox-inbox-p1"><font face="monospace">merge [x] [] = [x]</font></p><p class="m_3279232060946607623inbox-inbox-p1"><font face="monospace">merge [] [y] = [y]</font></p><p class="m_3279232060946607623inbox-inbox-p1"><font face="monospace">merge first@(x:xs) second@(y:ys) | x <= y = x : merge xs second</font></p><p class="m_3279232060946607623inbox-inbox-p1"><font face="monospace"> | otherwise = y : merge first ys</font></p><div><br></div></div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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-bin/mailman/listinfo/beginners</a><br>
</blockquote></div></div></div></div>