[Haskell-cafe] function unique
hughperkins at gmail.com
Wed Jul 11 16:25:58 EDT 2007
Simple answer: you always have to have the single element first, then the
list bit second. It's just the way it is. You can learn why later on ;-)
On 7/11/07, Alexteslin <alexteslin at yahoo.co.uk> wrote:
> 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
> 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
> 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'
> > 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:
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe