Skip to content

Instantly share code, notes, and snippets.

@rrodseth
Last active May 10, 2018 04:03
Show Gist options
  • Save rrodseth/e6227bf559d7ff26a410d57be166656a to your computer and use it in GitHub Desktop.
Save rrodseth/e6227bf559d7ff26a410d57be166656a to your computer and use it in GitHub Desktop.
-- Function which takes the name of a month ("May") and the number of days in that month (31),
-- and returns a list of all the dates in that month (["May 1", ..., "May 31"]).
-- using map
datesInMonth :: String -> Int -> [String]
datesInMonth month days = map (\x -> month ++ " " ++ show x) [1..days]
-- using list comprehension
datesInMonth2 :: String -> Int -> [String]
datesInMonth2 month days = [ month ++ " " ++ show i | i <- [1..days]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment