Created
April 11, 2019 15:16
-
-
Save captainalan/3b76dbb9a11027a6e8d3e67c1ff426e9 to your computer and use it in GitHub Desktop.
Haskell Practice: List Sorted on Second Element of Tuple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- Write a program which returns a list of sorted tuples based on the | |
- second element: | |
- e.g. tuple_list = [ (a, 5), (b, 2), (c, 3), (d, 1), (e, 4) ] | |
- Output: [d, b, c, e, a] | |
-} | |
import Data.Tuple | |
import Data.List | |
foo :: (Ord b) => [(a, b)] -> [a] | |
foo xs = map fst sorted | |
where sorted = sortOn snd xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment