[Haskell-cafe] function unique

Alexteslin alexteslin at yahoo.co.uk
Wed Jul 11 15:59:52 EDT 2007


Oh, I am lost now - for now anyway.  
I am attempting to do next exercise in the book to define reverse function
using primitive recursion and pattern matching on lists.  But getting stack
because when i con in front of xs (xs:x) i get en error, which i thought i
would be getting anyway.  I tried to define a helper function and cons there
in front of xs and i get type errors again.

I know these are easy and boring questions but i would appreciate a hint.

Thank you


Neil Mitchell wrote:
> 
> Hi
> 
>> unique = unique' []
>>
>> unique' _ [] = []
>> unique' history (x:xs) = if x `elem` history
>>   then next
>>   else (x:next) where next = (uniq' (x:hist) xs)
> 
> You can express this more neatly:
> 
> unique' _ [] = []
> unique' history (x:xs) = [x | x `notElem` history] ++ unique' (x:history)
> xs
> 
> Thanks
> 
> Neil
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

-- 
View this message in context: http://www.nabble.com/function-unique-tf4058328.html#a11547781
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list