[Haskell-cafe] function unique

Hugh Perkins 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
> 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.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070711/9fe7508c/attachment-0001.htm


More information about the Haskell-Cafe mailing list