summaryrefslogtreecommitdiff
path: root/gcd.hs
diff options
context:
space:
mode:
Diffstat (limited to 'gcd.hs')
-rw-r--r--gcd.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/gcd.hs b/gcd.hs
new file mode 100644
index 0000000..764e824
--- /dev/null
+++ b/gcd.hs
@@ -0,0 +1,11 @@
+import Control.Monad.Writer
+
+gcd' :: Int -> Int -> Writer [String] Int
+gcd' a b
+ | b == 0 = do
+ tell ["Finished with " ++ show a]
+ return a
+ | otherwise = do
+ tell [show a ++ " mod " ++ show b ++ " = " ++ show (a `mod` b)]
+ gcd' b (a `mod` b)
+