Skip to content

Instantly share code, notes, and snippets.

@ljsc
Created September 2, 2010 14:04
Show Gist options
  • Save ljsc/562323 to your computer and use it in GitHub Desktop.
Save ljsc/562323 to your computer and use it in GitHub Desktop.
(x:xs) `minus` yys@(y:ys)
| x == y = xs `minus` ys
| otherwise = x : xs `minus` yys
naturals = [1..]
evens = [2,4..]
odds = naturals `minus` evens
{-
*Main> take 10 naturals
[1,2,3,4,5,6,7,8,9,10]
*Main> take 10 odds
[1,3,5,7,9,11,13,15,17,19]
*Main> take 10 evens
[2,4,6,8,10,12,14,16,18,20]
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment