From 8e73d89184790e92e8a1fd6b045de7a658f918d6 Mon Sep 17 00:00:00 2001 From: lulucca12 Date: Mon, 2 Jul 2018 14:01:07 -0300 Subject: [PATCH 1/4] Modified code to be more clear and readable and to avoid hiding values inside "where" bindings. --- .../code/haskell/euclidean_example.hs | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/chapters/euclidean_algorithm/code/haskell/euclidean_example.hs b/chapters/euclidean_algorithm/code/haskell/euclidean_example.hs index e292e3457..ed7929730 100644 --- a/chapters/euclidean_algorithm/code/haskell/euclidean_example.hs +++ b/chapters/euclidean_algorithm/code/haskell/euclidean_example.hs @@ -1,25 +1,22 @@ -- contributed by Nicole Mazzuca (ubsan) - euclidSub :: Integer -> Integer -> Integer -euclidSub a b = inner (abs a) (abs b) where - inner a b = - if a == b then - a - else if a < b then - euclidSub a (b - a) - else - euclidSub (a - b) b +euclidSub a b = inner (abs a) (abs b) + where + inner x y + | x == y = x + | x < y = euclidSub x (y - x) + | otherwise = euclidSub (x - y) y euclidMod :: Integer -> Integer -> Integer -euclidMod a b = inner (abs a) (abs b) where - inner a 0 = a - inner a b = inner b (a `mod` b) +euclidMod a b = inner (abs a) (abs b) + where + inner x 0 = x + inner x y = inner y (x `mod` y) main :: IO () main = do let chk1 = euclidMod (64 * 67) (64 * 81) chk2 = euclidSub (128 * 12) (128 * 77) - putStrLn (show chk1) - putStrLn (show chk2) + print chk1 + print chk2 return () - From 5c5ddc916039fae8d193616813ea5f0b858bc6b5 Mon Sep 17 00:00:00 2001 From: lulucca12 Date: Mon, 2 Jul 2018 15:28:48 -0300 Subject: [PATCH 2/4] Edited the chapter file --- chapters/euclidean_algorithm/euclidean.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chapters/euclidean_algorithm/euclidean.md b/chapters/euclidean_algorithm/euclidean.md index 609271b47..d0425f3c5 100644 --- a/chapters/euclidean_algorithm/euclidean.md +++ b/chapters/euclidean_algorithm/euclidean.md @@ -20,7 +20,7 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two {% sample lang="py" %} [import:11-22, lang="python"](code/python/euclidean_example.py) {% sample lang="haskell" %} -[import:3-11, lang="haskell"](code/haskell/euclidean_example.hs) +[import:2-8, lang="haskell"](code/haskell/euclidean_example.hs) {% sample lang="rs" %} [import:3-15, lang="rust"](code/rust/euclidean_example.rs) {% sample lang="ml" %} @@ -53,7 +53,7 @@ Modern implementations, though, often use the modulus operator (%) like so {% sample lang="py" %} [import:1-9, lang="python"](code/python/euclidean_example.py) {% sample lang="haskell" %} -[import:13-24, lang="haskell"](code/haskell/euclidean_example.hs) +[import:10-22, lang="haskell"](code/haskell/euclidean_example.hs) {% sample lang="rs" %} [import:17-27, lang="rust"](code/rust/euclidean_example.rs) {% sample lang="ml" %} @@ -136,4 +136,3 @@ $$ \newcommand{\bfomega}{\boldsymbol{\omega}} \newcommand{\bftau}{\boldsymbol{\tau}} $$ - From c9db3228d1da9d405b66752f121aee39bf8dcaf0 Mon Sep 17 00:00:00 2001 From: lulucca12 Date: Mon, 2 Jul 2018 17:02:19 -0300 Subject: [PATCH 3/4] Corrected "euclidian.md" file and added my name to the CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + chapters/euclidean_algorithm/euclidean.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 807513539..0323542f6 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -14,3 +14,4 @@ Unlambder Kjetil Johannessen CDsigma DominikRafacz +lulucca12 diff --git a/chapters/euclidean_algorithm/euclidean.md b/chapters/euclidean_algorithm/euclidean.md index d0425f3c5..cdf01402a 100644 --- a/chapters/euclidean_algorithm/euclidean.md +++ b/chapters/euclidean_algorithm/euclidean.md @@ -53,7 +53,7 @@ Modern implementations, though, often use the modulus operator (%) like so {% sample lang="py" %} [import:1-9, lang="python"](code/python/euclidean_example.py) {% sample lang="haskell" %} -[import:10-22, lang="haskell"](code/haskell/euclidean_example.hs) +[import:10-14, lang="haskell"](code/haskell/euclidean_example.hs) {% sample lang="rs" %} [import:17-27, lang="rust"](code/rust/euclidean_example.rs) {% sample lang="ml" %} From 1b0ab8e2e78a8055ed05a8370a36e6ab66ecbe4a Mon Sep 17 00:00:00 2001 From: lulucca12 Date: Mon, 2 Jul 2018 22:19:32 -0300 Subject: [PATCH 4/4] Remove the 'return ()' --- chapters/euclidean_algorithm/code/haskell/euclidean_example.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/chapters/euclidean_algorithm/code/haskell/euclidean_example.hs b/chapters/euclidean_algorithm/code/haskell/euclidean_example.hs index ed7929730..e09b450c9 100644 --- a/chapters/euclidean_algorithm/code/haskell/euclidean_example.hs +++ b/chapters/euclidean_algorithm/code/haskell/euclidean_example.hs @@ -19,4 +19,3 @@ main = do chk2 = euclidSub (128 * 12) (128 * 77) print chk1 print chk2 - return ()