Combined two styles: pattern-matching vs if-then-else

Pattern matching (from book), if-then-else (from original code)
This commit is contained in:
Tong-Kiat Tan 2014-08-10 09:03:14 +08:00
parent d6ab918c51
commit 8f9c4d2b23

View File

@ -13,14 +13,28 @@ main = do
phash3 <- imageHash "image3.jpg"
putStrLn $ "image3: " ++ show phash3
if isJust phash1 && isJust phash2 then do
putStr "hamming distance between image1 and image2: "
print $ hammingDistance (fromJust phash1) (fromJust phash2)
else
print "Error, could not read images"
if isJust phash1 && isJust phash3 then do
putStr "hamming distance between image1 and image3: "
print $ hammingDistance (fromJust phash1) (fromJust phash3)
else
print "Error, could not read images"
{-
case (phash1, phash2) of
(Just h1, Just h2) -> do
putStr "hammind distance: "
putStr "hamming distance between image1 and image2: "
print $ hammingDistance h1 h2
_ -> putStrLn "Error, could not read images"
case (phash1, phash3) of
(Just h1, Just h3) -> do
putStr "hammind distance: "
putStr "hamming distance between image1 and image3: "
print $ hammingDistance h1 h3
_ -> putStrLn "Error, could not read images"
-}