<div><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 11, 2020 at 1:42 AM Alexander Chen <<a href="mailto:alexander@chenjia.nl">alexander@chenjia.nl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-family:Arial;font-size:13px">hi,<div><br></div><div>assigment: make your own element function with the any function.</div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Courier New",monospace;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:#6a9955">--elem with any</span></div><div><span style="color:#dcdcaa">myElemAny</span> :: <span style="color:#569cd6">Eq</span> <span style="color:#9cdcfe">a</span> => <span style="color:#9cdcfe">a</span> -> [<span style="color:#9cdcfe">a</span>] -> <span style="color:#569cd6">Bool</span></div><div>myElemAny a = any (== a)</div><br><div><span style="color:#6a9955">--elem with any</span></div><div><span style="color:#dcdcaa">myElemAny'</span> :: <span style="color:#569cd6">Eq</span> <span style="color:#9cdcfe">a</span> => <span style="color:#9cdcfe">a</span> -> [<span style="color:#9cdcfe">a</span>] -> <span style="color:#569cd6">Bool</span></div><div>myElemAny' a [x]= any (== a) [x]</div></div><br><div><div style="font-family:Arial;font-size:13px"></div></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">From a beginners perspective, the second function looks perfectly cromulent. After all, how should one indicate a list if not by enclosing it with square brackets like this, [x]? </div><div dir="auto"><br></div><div dir="auto">An x might or might not be a list, but [x] surely has to be one, yes?</div><div dir="auto"><br></div><div dir="auto">But consider all the things that could be a list. Specifically, look at the following:</div><div dir="auto"><br></div><div dir="auto">1. An empty list—which haskell denotes using []—is a list</div><div dir="auto">2. [1,2,3] is a list</div><div dir="auto">3. [1,1,1,…] is a list</div><div dir="auto"><br></div><div dir="auto">In each of the cases above, what is the value of x in [x]?</div><div dir="auto"><br></div><div dir="auto">Recall that haskell is a value-oriented language. Every identifier at the term-level evaluates to something that has a well-defined type.</div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-family:Arial;font-size:13px"><div><div><div style="font-family:Arial;font-size:13px"><br></div></div></div><div style="font-family:Arial;font-size:13px">myElemAny' compiles but throws an error because it has a non-exhaustive pattern. Could somebody tell me why the list gives the function grieveness?</div><div style="font-family:Arial;font-size:13px"><br></div><div style="font-family:Arial;font-size:13px">thanks,</div><div style="font-family:Arial;font-size:13px"><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>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">-- Kim-Ee</div>