<br><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2) The list might be infinite, and your function should work if you make<br>only want to use the first part of it, so the following should return
<br>[1,2,3,4,5] in a finite amount of time:<br><br>take 5 (unique [1..])</blockquote><br>I don&#39;t think this is possible.&nbsp; Perhaps you misread the original problem description?&nbsp; The unique function is supposed to return a list of those elements which occur exactly once in the input list, which is impossible to determine for an infinite input list (the only way to prove that a given element occurs only once in a list, in the absence of any other information, is to examine every element of the list).&nbsp; Of course, a function that behaves like the unix utility &quot;uniq&quot; (
i.e. returning only one copy of every list element) is possible to implement lazily in the manner you describe.<br><br>@Alexteslin: It probably would still be a useful exercise for you, though, to get rid of the redundancy Dan describes in determining whether to keep each element.&nbsp; A function to count the occurrences of a given element (although useful in its own right) is overkill here, since you only care whether the element occurs once, or more than once.&nbsp; You could implement a function isUnique :: Int -&gt; [Int] -&gt; Bool which tells you whether the given element occurs only once (True) or more than once (False), and doesn&#39;t evaluate more of the list than necessary to determine this.&nbsp; I doubt you&#39;d have much trouble implementing this function.
<br><br>-Brent<br></div>