<br><br><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">><br>> I don't think this is possible. Perhaps you misread the original problem
<br>> description? The unique function is supposed to return a list of those<br>> elements which occur exactly once in the input list, which is impossible to<br>> determine for an infinite input list (the only way to prove that a given
<br>> element occurs only once in a list, in the absence of any other information,<br>> is to examine every element of the list). Of course, a function that<br>> behaves like the unix utility "uniq" (
i.e. returning only one copy of every<br>> list element) is possible to implement lazily in the manner you describe.<br><br>Why wouldn't this work? (I haven't tested it, sorry)<br><br>unique = unique' <br>
<br>unique' _  = <br>unique' history (x:xs) = if x `elem` history<br> then next<br> else (x:next) where next = (uniq' (x:hist) xs)</blockquote><div><br>Again, this is solving a different problem than what the OP stated. Using your definition:
<br><br> Prelude> :l unique<br>[1 of 1] Compiling Main ( unique.hs, interpreted )<br>Ok, modules loaded: Main.<br>*Main> unique [1,2,3,1]<br>[1,2,3]<br>*Main> <br><br></div>...which behaves like the Unix utility 'uniq'. But the problem described originally is to write a function which produces [2,3] when given the same input; 1 is not included in the output since it occurs more than once.