<div dir="ltr">Hi Trent, <div><br></div><div>
<i><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">why </span><font face="monospace" size="2" style="color:rgb(34,34,34);font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">first == first@(x:xs)</font><font size="2" style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">, especially weather the variable declarations are considered names for the same thing.</font> </i><br></div><div><br></div><div>first@(x:xs) is meant to be read as below:</div><div><br></div><div>"first as (x:xs)". </div><div><br></div><div>This is syntactic sugar that gives you the flexibility to address the entire list as "first", the first element (head) of the list as "x" and the rest of the list (tail) as xs. </div><div><br></div><div>If you don't want to use @, you can write the last case in your program as: </div><div><br></div><div>
<p class="m_1854167135293228937gmail-m_-7547731111719701566inbox-inbox-p1" style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace">merge first second | (head first) <= (head second) = (head first) : merge (tail first) second</font></p><p class="m_1854167135293228937gmail-m_-7547731111719701566inbox-inbox-p1" style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace"> | otherwise = (head second): merge first (tail second) </font></p>
<br></div><div>instead of </div><div><br></div><div>
<p class="m_1854167135293228937gmail-m_-7547731111719701566inbox-inbox-p1" style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace">merge first@(x:xs) second@(y:ys) | x <= y = x : merge xs second</font></p><p class="m_1854167135293228937gmail-m_-7547731111719701566inbox-inbox-p1" style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><font face="monospace"> | otherwise = y : merge first ys</font></p>
<br></div><div>Relevant SO question : <a href="https://stackoverflow.com/questions/1153465/what-does-the-symbol-mean-in-reference-to-lists-in-haskell" target="_blank">https://stackoverflow.com/questions/1153465/what-does-the-symbol-mean-in-reference-to-lists-in-haskell</a></div><div><br></div><div>
<i><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">why </span><font face="monospace" size="2" style="color:rgb(34,34,34);font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">[x] /= xs</font> </i><br></div><div><i><br></i></div><div>when you call merge as: </div><div><br></div><div>> merge first second</div><div><br></div><div>from merge type signature,</div><div><br></div><div>
<span style="color:rgb(34,34,34);font-family:monospace;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">merge :: Ord a => [a] -> [a] -> [a]</span> <br></div><div><br></div><div>
<span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>we know it takes </span> two lists of type a, belonging to typeclass Ord (where <, > has meaning)</div><div><br></div><div>first & second checked for being a list & whatever is present inside the list is expected to be of typeclass Ord. <br></div><div><br></div><div>Case A: If you wrote merge [x] [] = [x] </div><div><br></div><div>[x] is expected to be a list of Ord</div><div>which means x is expected to be Ord. </div><div><br></div><div>Case B: if you called merge x [] = x</div><div><br></div><div>x is expected to be a list of Ord.</div><div><br></div><div>When you call merge [4,5] []</div><div><br></div><div>In Case A, it implies "4,5" is a member of Ord, as this is x. Which it isn't (as 3 <"4,5" has no meaning). Therefore merge [x] [] = [x] isn't executed here, the program goes looking for other cases & doesn't find any that satisfies these input types & leads to the error you encountered. </div><div><br></div><div>In Case B, it imples [4,5] is a list of Ords, which corresponds to the correct type. Therefore this statement is executed. </div><div><br></div><div>Regards, Hemanth</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, May 18, 2018 at 11:34 AM trent shipley <<a href="mailto:trent.shipley@gmail.com" target="_blank">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">Thanks to all. I used Mukesh's suggestion. <div><br></div><div>I am still not clear on:</div><div><br></div><div>why <font face="monospace" size="2">[x] /= xs</font></div><div>why <font face="monospace" size="2">first == first@(x:xs)</font><font size="2">, especially weather the variable declarations are considered names for the same thing.</font></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 17, 2018 at 10:39 PM Hemanth Gunda <<a href="mailto:hemanth.420@gmail.com" target="_blank">hemanth.420@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">Hi Trent, <div><br></div><div>This works: </div></div><div dir="ltr"><div><br></div><div>
<div style="color:rgb(248,248,242);background-color:rgb(39,40,34);font-family:Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(166,226,46)">merge</span><span style="color:rgb(249,38,114)">::</span><span style="color:rgb(248,248,242)"> </span><span style="color:rgb(102,217,239);font-style:italic">Ord</span><span style="color:rgb(248,248,242)"> </span><span style="color:rgb(248,248,242)">a</span><span style="color:rgb(248,248,242)"> </span><span style="color:rgb(249,38,114)">=></span><span style="color:rgb(248,248,242)"> [</span><span style="color:rgb(248,248,242)">a</span><span style="color:rgb(248,248,242)">] </span><span style="color:rgb(249,38,114)">-></span><span style="color:rgb(248,248,242)"> [</span><span style="color:rgb(248,248,242)">a</span><span style="color:rgb(248,248,242)">] </span><span style="color:rgb(249,38,114)">-></span><span style="color:rgb(248,248,242)"> [</span><span style="color:rgb(248,248,242)">a</span><span style="color:rgb(248,248,242)">]</span></div><div><span style="color:rgb(248,248,242)">merge </span><span style="color:rgb(174,129,255)">[]</span><span style="color:rgb(248,248,242)"> </span><span style="color:rgb(174,129,255)">[]</span><span style="color:rgb(248,248,242)"> </span><span style="color:rgb(249,38,114)">=</span><span style="color:rgb(248,248,242)"> </span><span style="color:rgb(174,129,255)">[]</span></div><div><span style="color:rgb(248,248,242)">merge x </span><span style="color:rgb(174,129,255)">[]</span><span style="color:rgb(248,248,242)"> </span><span style="color:rgb(249,38,114)">=</span><span style="color:rgb(248,248,242)"> x</span></div><div><span style="color:rgb(248,248,242)">merge </span><span style="color:rgb(174,129,255)">[]</span><span style="color:rgb(248,248,242)"> y </span><span style="color:rgb(249,38,114)">=</span><span style="color:rgb(248,248,242)"> y</span></div><div><span style="color:rgb(248,248,242)">merge first</span><span style="color:rgb(249,38,114)">@</span><span style="color:rgb(248,248,242)">(x</span><span style="color:rgb(249,38,114)">:</span><span style="color:rgb(248,248,242)">xs) second</span><span style="color:rgb(249,38,114)">@</span><span style="color:rgb(248,248,242)">(y</span><span style="color:rgb(249,38,114)">:</span><span style="color:rgb(248,248,242)">ys) </span></div><div><span style="color:rgb(248,248,242)"> </span><span style="color:rgb(249,38,114)">|</span><span style="color:rgb(248,248,242)"> x </span><span style="color:rgb(249,38,114)"><=</span><span style="color:rgb(248,248,242)"> y </span><span style="color:rgb(249,38,114)">=</span><span style="color:rgb(248,248,242)"> x </span><span style="color:rgb(249,38,114)">:</span><span style="color:rgb(248,248,242)"> merge xs second </span></div><div><span style="color:rgb(248,248,242)"> </span><span style="color:rgb(249,38,114)">|</span><span style="color:rgb(248,248,242)"> otherwise </span><span style="color:rgb(249,38,114)">=</span><span style="color:rgb(248,248,242)"> y </span><span style="color:rgb(249,38,114)">:</span><span style="color:rgb(248,248,242)"> merge first ys</span></div></div>
<br></div></div><div dir="ltr"><div>Difference in the lines</div></div><div dir="ltr"><div><br></div><div>
<div style="font-family:Consolas,"Courier New",monospace;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font color="#000000">merge x [] = x</font></div><div style="font-family:Consolas,"Courier New",monospace;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><font color="#000000">merge [] y = y</font></div></div><div><br></div></div><div dir="ltr"><div>As the input is of type [a] where a belongs to typeclass Ord, you must pass x instead of [x]. </div><div><br></div><div>[x] would work if you tried merge [4] []. but will fail if you tried merge [4,5] []. because "4,5" isn't of type a. </div><div><br></div><div>Regards, Hemanth</div><div><br></div></div><br><div class="gmail_quote"></div><div class="gmail_quote"><div dir="ltr">On Fri, May 18, 2018 at 10:51 AM trent shipley <<a href="mailto:trent.shipley@gmail.com" target="_blank">trent.shipley@gmail.com</a>> wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-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_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><font face="monospace">merge [] []</font> works.</p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><font face="monospace">merge [1] [] </font>works.</p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1">I don't know why the failing example fails. It should return:</p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><font face="monospace">[4,5]</font></p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1">Help to unstuck is appreciated.</p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><span class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-s1"><font face="monospace">:step merge [4,5] []</font></span></p>
<p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><span class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-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_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1">Given:</p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><font face="monospace">merge :: Ord a => [a] -> [a] -> [a]</font></p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><font face="monospace">merge [] [] = []</font></p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><font face="monospace">merge [x] [] = [x]</font></p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><font face="monospace">merge [] [y] = [y]</font></p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><font face="monospace">merge first@(x:xs) second@(y:ys) | x <= y = x : merge xs second</font></p><p class="m_1854167135293228937m_628167459452661061m_8601678838629474277m_-7547731111719701566inbox-inbox-p1"><font face="monospace"> | otherwise = y : merge first ys</font></p><div><br></div></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
_______________________________________________<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>
_______________________________________________<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>
_______________________________________________<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>