Skip to content

Instantly share code, notes, and snippets.

@ConnorBaker
Last active February 23, 2019 00:50
Show Gist options
  • Select an option

  • Save ConnorBaker/00d388cc2d844d3dd9a56e4c57ee6fc7 to your computer and use it in GitHub Desktop.

Select an option

Save ConnorBaker/00d388cc2d844d3dd9a56e4c57ee6fc7 to your computer and use it in GitHub Desktop.
Programming in Haskell, 2nd ed.: Chapter 5: Problem 8
find :: Eq a => a -> [(a,b)] -> [b]
find k t = [v | (k',v) <- t, k == k']
positions :: Eq a => a -> [a] -> [Int]
positions x xs = [i | (x',i) <- zip xs [0..], x == x']
positions' :: Eq a => a -> [a] -> [Int]
positions' x xs = find x (zip xs [0..])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment