Last Friday of each month: Difference between revisions

m
(→‎{{header|Julia}}: A new entry for Julia)
Line 561:
 
=={{header|Haskell}}==
<lang Haskell>module Rosettataskimport Data.Time.Calendar
where
import Data.Time.Calendar
import Data.Time.Calendar.WeekDate
 
findFriday ::date Day= head $ filter isFriday $ map toDate [->6 .. Day0]
where
findFriday date = head $ filter isFriday $ map toDate [0, -1 .. -7]
toDate ago = addDays ago date
where
isFriday theDate = let (_ , _ , d day) = toWeekDate theDate
toDate :: Integer -> Day
in day == 5
toDate ago = addDays ago date
isFriday :: Day -> Bool
isFriday theDate = d == 5
where
(_ , _ , d ) = toWeekDate theDate
 
fridayDates ::year Integer= ->map [String](showGregorian . findFriday) lastDaysInMonth
where
fridayDates year = map ( showGregorian . findFriday ) lastDaysInMonth
lastDaysInMonth = map findLastDay [1 .. 12]
where
findLastDay month = fromGregorian year month ( gregorianMonthLength year month)
lastDaysInMonth = map findLastDay [1 .. 12]
findLastDay month = fromGregorian year month ( gregorianMonthLength
year month )
 
main = do
putStrLn "Please enter a year!"
year <- getLine
mapM_ putStrLn $ fridayDates ( read year )</lang>
{{out}}
<pre>Please enter a year!
Anonymous user