From 8bf90adea31f535806cf589e5c05fa0faaca873a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Gillet?= Date: Fri, 24 Apr 2020 23:14:14 +0900 Subject: [PATCH 1/5] Added Haskell --- .../computus/code/haskell/gauss_easter.hs | 64 +++++++++++++++++++ contents/computus/computus.md | 2 + 2 files changed, 66 insertions(+) create mode 100644 contents/computus/code/haskell/gauss_easter.hs diff --git a/contents/computus/code/haskell/gauss_easter.hs b/contents/computus/code/haskell/gauss_easter.hs new file mode 100644 index 000000000..b5cf48a19 --- /dev/null +++ b/contents/computus/code/haskell/gauss_easter.hs @@ -0,0 +1,64 @@ +data Mode = Servois | Easter + +computus :: Mode -> Int -> String +computus mode year = + let + -- Year's position on the 19 year metonic cycle + a = year `mod` 19 + + -- Century index + k = year `div` 100 + + -- Shift of metonic cycle, add a day offset every 300 years + p = (13 + 8 * k) `div` 25 + + -- Correction for non-observed leap days + q = k `div` 4 + + -- Correction to starting point of calculation each century + m = (15 - p + k - q) `mod` 30 + + -- Number of days from March 21st until the full moon + d = (19 * a + m) `mod` 30 + in + case mode of + -- Returning if user wants value for Servois' table + Servois -> + show $ (21 + d) `mod` 31 + + -- Finding the next Sunday + Easter -> + let + -- Century-based offset in weekly calculation + n = (4 + k - q) `mod` 7 + + -- Correction for leap days + b = year `mod` 4 + c = year`mod` 7 + + -- Days from d to next Sunday + e = (2 * b + 4 * c + 6 * d + n) `mod` 7 + + -- Historical corrections for April 26 and 25 + f = if (d == 29 && e == 6) || (d == 28 && e == 6 && a > 10) + then e - 1 + else e + in + -- Determination of the correct month for Easter + if 22+ d + f > 31 + then "April " ++ show (d + f - 9) + else "March " ++ show (22 + d + f) + + +-- Here, we will output the date of the Paschal full moon +-- (using Servois notation), and Easter for 2020-2030 +main :: IO () +main = do + let years = [2020..2030] + servoisNumbers = map (computus Servois) years + easterDates = map (computus Easter) years + putStrLn "The following are the dates of the Paschal full moon (using Servois notation) and the date of Easter for 2020-2030 AD:" + putStrLn "Year\tServois number\tEaster" + let conc y s e = show y ++ "\t" ++ s ++ "\t\t" ++ e + mapM_ putStrLn $ zipWith3 conc years servoisNumbers easterDates + diff --git a/contents/computus/computus.md b/contents/computus/computus.md index 30d2ca16b..81d72530f 100644 --- a/contents/computus/computus.md +++ b/contents/computus/computus.md @@ -281,6 +281,8 @@ For now, we have the code outputting a tuple of $$d$$ and $$e$$, so users can us {% method %} {% sample lang="jl" %} [import, lang:"julia"](code/julia/gauss_easter.jl) +{% sample lang="hs" %} +[import, lang:"haskell"](code/haskell/gauss_easter.hs) {% endmethod %} From 716773b618f708f08611c42785c7d659f1006123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Gillet?= Date: Fri, 24 Apr 2020 23:25:25 +0900 Subject: [PATCH 2/5] Fixed f --- contents/computus/code/haskell/gauss_easter.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/computus/code/haskell/gauss_easter.hs b/contents/computus/code/haskell/gauss_easter.hs index b5cf48a19..bb22f7404 100644 --- a/contents/computus/code/haskell/gauss_easter.hs +++ b/contents/computus/code/haskell/gauss_easter.hs @@ -41,7 +41,7 @@ computus mode year = -- Historical corrections for April 26 and 25 f = if (d == 29 && e == 6) || (d == 28 && e == 6 && a > 10) - then e - 1 + then -1 else e in -- Determination of the correct month for Easter From 2aacc44b15b487a093dfa5aee8c7c8bf9dc3f42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Gillet?= Date: Sun, 24 May 2020 10:57:41 +0900 Subject: [PATCH 3/5] Different arrangement --- .../computus/code/haskell/gauss_easter.hs | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/contents/computus/code/haskell/gauss_easter.hs b/contents/computus/code/haskell/gauss_easter.hs index bb22f7404..3a2189476 100644 --- a/contents/computus/code/haskell/gauss_easter.hs +++ b/contents/computus/code/haskell/gauss_easter.hs @@ -2,7 +2,17 @@ data Mode = Servois | Easter computus :: Mode -> Int -> String computus mode year = - let + case mode of + Servois -> + -- Value for Servois' table + show $ (21 + d) `mod` 31 + + Easter -> + -- Determination of the correct month for Easter + if 22+ d + f > 31 + then "April " ++ show (d + f - 9) + else "March " ++ show (22 + d + f) + where -- Year's position on the 19 year metonic cycle a = year `mod` 19 @@ -20,35 +30,22 @@ computus mode year = -- Number of days from March 21st until the full moon d = (19 * a + m) `mod` 30 - in - case mode of - -- Returning if user wants value for Servois' table - Servois -> - show $ (21 + d) `mod` 31 - - -- Finding the next Sunday - Easter -> - let - -- Century-based offset in weekly calculation - n = (4 + k - q) `mod` 7 - -- Correction for leap days - b = year `mod` 4 - c = year`mod` 7 + -- Finding the next Sunday + -- Century-based offset in weekly calculation + n = (4 + k - q) `mod` 7 - -- Days from d to next Sunday - e = (2 * b + 4 * c + 6 * d + n) `mod` 7 + -- Correction for leap days + b = year `mod` 4 + c = year `mod` 7 - -- Historical corrections for April 26 and 25 - f = if (d == 29 && e == 6) || (d == 28 && e == 6 && a > 10) - then -1 - else e - in - -- Determination of the correct month for Easter - if 22+ d + f > 31 - then "April " ++ show (d + f - 9) - else "March " ++ show (22 + d + f) + -- Days from d to next Sunday + e = (2 * b + 4 * c + 6 * d + n) `mod` 7 + -- Historical corrections for April 26 and 25 + f = if (d == 29 && e == 6) || (d == 28 && e == 6 && a > 10) + then -1 + else e -- Here, we will output the date of the Paschal full moon -- (using Servois notation), and Easter for 2020-2030 From d75f37fbc8d67eefbec3bd2650ee5d887d614d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Gillet?= Date: Wed, 27 May 2020 11:48:29 +0900 Subject: [PATCH 4/5] Adding type annotations and format with ormolu --- .../computus/code/haskell/gauss_easter.hs | 73 ++++++++----------- 1 file changed, 32 insertions(+), 41 deletions(-) diff --git a/contents/computus/code/haskell/gauss_easter.hs b/contents/computus/code/haskell/gauss_easter.hs index 3a2189476..678d40328 100644 --- a/contents/computus/code/haskell/gauss_easter.hs +++ b/contents/computus/code/haskell/gauss_easter.hs @@ -2,60 +2,51 @@ data Mode = Servois | Easter computus :: Mode -> Int -> String computus mode year = - case mode of - Servois -> - -- Value for Servois' table - show $ (21 + d) `mod` 31 - - Easter -> - -- Determination of the correct month for Easter - if 22+ d + f > 31 - then "April " ++ show (d + f - 9) - else "March " ++ show (22 + d + f) + case mode of + Servois -> + -- Value for Servois' table + show $ (21 + d) `mod` 31 + Easter -> + -- Determination of the correct month for Easter + if 22 + d + f > 31 + then "April " ++ show (d + f - 9) + else "March " ++ show (22 + d + f) where -- Year's position on the 19 year metonic cycle - a = year `mod` 19 - + a = year `mod` 19 :: Int -- Century index - k = year `div` 100 - + k = year `div` 100 :: Int -- Shift of metonic cycle, add a day offset every 300 years - p = (13 + 8 * k) `div` 25 - + p = (13 + 8 * k) `div` 25 :: Int -- Correction for non-observed leap days - q = k `div` 4 - + q = k `div` 4 :: Int -- Correction to starting point of calculation each century - m = (15 - p + k - q) `mod` 30 - + m = (15 - p + k - q) `mod` 30 :: Int -- Number of days from March 21st until the full moon - d = (19 * a + m) `mod` 30 - + d = (19 * a + m) `mod` 30 :: Int -- Finding the next Sunday -- Century-based offset in weekly calculation - n = (4 + k - q) `mod` 7 - + n = (4 + k - q) `mod` 7 :: Int -- Correction for leap days - b = year `mod` 4 - c = year `mod` 7 - + b = year `mod` 4 :: Int + c = year `mod` 7 :: Int -- Days from d to next Sunday - e = (2 * b + 4 * c + 6 * d + n) `mod` 7 - + e = (2 * b + 4 * c + 6 * d + n) `mod` 7 :: Int -- Historical corrections for April 26 and 25 - f = if (d == 29 && e == 6) || (d == 28 && e == 6 && a > 10) - then -1 - else e + f = + if (d == 29 && e == 6) || (d == 28 && e == 6 && a > 10) + then -1 :: Int + else e :: Int -- Here, we will output the date of the Paschal full moon -- (using Servois notation), and Easter for 2020-2030 main :: IO () -main = do - let years = [2020..2030] - servoisNumbers = map (computus Servois) years - easterDates = map (computus Easter) years - putStrLn "The following are the dates of the Paschal full moon (using Servois notation) and the date of Easter for 2020-2030 AD:" - putStrLn "Year\tServois number\tEaster" - let conc y s e = show y ++ "\t" ++ s ++ "\t\t" ++ e - mapM_ putStrLn $ zipWith3 conc years servoisNumbers easterDates - +main = do + let years = [2020 .. 2030] :: [Int] + servoisNumbers = map (computus Servois) years :: [String] + easterDates = map (computus Easter) years :: [String] + putStrLn "The following are the dates of the Paschal full moon (using Servois notation) and the date of Easter for 2020-2030 AD:" + putStrLn "Year\tServois number\tEaster" + let conc :: Int -> String -> String -> String + conc y s e = show y ++ "\t" ++ s ++ "\t\t" ++ e + mapM_ putStrLn $ zipWith3 conc years servoisNumbers easterDates From b58aebbd881e211d1e553cfcdd4dc9adcaffdec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Gillet?= Date: Sat, 30 May 2020 10:32:43 +0900 Subject: [PATCH 5/5] Type signature on seperate line --- .../computus/code/haskell/gauss_easter.hs | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/contents/computus/code/haskell/gauss_easter.hs b/contents/computus/code/haskell/gauss_easter.hs index 678d40328..a6ab70244 100644 --- a/contents/computus/code/haskell/gauss_easter.hs +++ b/contents/computus/code/haskell/gauss_easter.hs @@ -12,39 +12,42 @@ computus mode year = then "April " ++ show (d + f - 9) else "March " ++ show (22 + d + f) where + a, b, c, d, e, f, k, m, n, p, q :: Int -- Year's position on the 19 year metonic cycle - a = year `mod` 19 :: Int + a = year `mod` 19 -- Century index - k = year `div` 100 :: Int + k = year `div` 100 -- Shift of metonic cycle, add a day offset every 300 years - p = (13 + 8 * k) `div` 25 :: Int + p = (13 + 8 * k) `div` 25 -- Correction for non-observed leap days - q = k `div` 4 :: Int + q = k `div` 4 -- Correction to starting point of calculation each century - m = (15 - p + k - q) `mod` 30 :: Int + m = (15 - p + k - q) `mod` 30 -- Number of days from March 21st until the full moon - d = (19 * a + m) `mod` 30 :: Int + d = (19 * a + m) `mod` 30 -- Finding the next Sunday -- Century-based offset in weekly calculation - n = (4 + k - q) `mod` 7 :: Int + n = (4 + k - q) `mod` 7 -- Correction for leap days - b = year `mod` 4 :: Int - c = year `mod` 7 :: Int + b = year `mod` 4 + c = year `mod` 7 -- Days from d to next Sunday - e = (2 * b + 4 * c + 6 * d + n) `mod` 7 :: Int + e = (2 * b + 4 * c + 6 * d + n) `mod` 7 -- Historical corrections for April 26 and 25 f = if (d == 29 && e == 6) || (d == 28 && e == 6 && a > 10) - then -1 :: Int - else e :: Int + then -1 + else e -- Here, we will output the date of the Paschal full moon -- (using Servois notation), and Easter for 2020-2030 main :: IO () main = do - let years = [2020 .. 2030] :: [Int] - servoisNumbers = map (computus Servois) years :: [String] - easterDates = map (computus Easter) years :: [String] + let years :: [Int] + years = [2020 .. 2030] + servoisNumbers, easterDates :: [String] + servoisNumbers = map (computus Servois) years + easterDates = map (computus Easter) years putStrLn "The following are the dates of the Paschal full moon (using Servois notation) and the date of Easter for 2020-2030 AD:" putStrLn "Year\tServois number\tEaster" let conc :: Int -> String -> String -> String