Skip to content

Instantly share code, notes, and snippets.

@jc99kuo
Created April 26, 2018 08:53
Show Gist options
  • Select an option

  • Save jc99kuo/05d0728b3b479465b0b1d62fa7c03aeb to your computer and use it in GitHub Desktop.

Select an option

Save jc99kuo/05d0728b3b479465b0b1d62fa7c03aeb to your computer and use it in GitHub Desktop.
FLOLAC 2018 Week 1 (2018-4-25 14:14) -- nub: filter out duplicating integers on a list
-- FLOLAC 2018 Week 1 -- nub: filter out duplicating integers on a list
nub :: [Int] -> [Int]
nub ix = dedup [] ix
where
dedup = \xs ys ->
case ys of
[] -> xs
(yhead:ytail) ->
if (elem yhead xs) then
dedup xs ytail
else
dedup (xs ++ [yhead]) ytail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment