-- setting the "warn-incomplete-patterns" flag asks GHC to warn you -- about possible missing cases in pattern-matching definitions {-# OPTIONS_GHC -fwarn-incomplete-patterns #-} -- see https://wiki.haskell.org/Safe_Haskell {-# LANGUAGE Safe #-} module Homework3 (gasUsage , luhnDouble , luhn) where import Types gasUsage :: (Fractional a, Ord a) => a -> Classification gasUsage g | g < 3 = Low | 3 <= g && g < 5 = Medium | 5 <= g && g < 7 = High | otherwise = SuperHigh luhnDouble :: Int -> Int luhnDouble x = let y = x * 2 in if y > 9 then y - 9 else y luhn :: Int -> Int -> Int -> Int -> Bool luhn a b c d = let x = [a, b, c, d] in sum ( map (\(i, y) -> if i `mod` 2 == 0 then luhnDouble y else y) (zip [1..4] (reverse x)) ) `mod` 10 == 0