summaryrefslogtreecommitdiff
path: root/gcd.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2014-08-07 16:38:13 +0800
committerJoe Zhao <ztuowen@gmail.com>2014-08-07 16:38:13 +0800
commitbc88e3464180e781e7ad2d552de0c8e496448d2e (patch)
tree56697567ecb8c49504014d58e2698870ad37514a /gcd.hs
downloadhaskbox-old-bc88e3464180e781e7ad2d552de0c8e496448d2e.tar.gz
haskbox-old-bc88e3464180e781e7ad2d552de0c8e496448d2e.tar.bz2
haskbox-old-bc88e3464180e781e7ad2d552de0c8e496448d2e.zip
Initial commit
Changes to be committed: new file: gcd.hs
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)
+