Skip to content

Instantly share code, notes, and snippets.

@mdippery
Created February 27, 2015 00:47
Show Gist options
  • Save mdippery/904edf00585f36c4c28d to your computer and use it in GitHub Desktop.
Save mdippery/904edf00585f36c4c28d to your computer and use it in GitHub Desktop.
Blood pressure calculator
import System.Console.GetOpt (ArgOrder(..), getOpt)
import System.Environment (getArgs, getProgName)
data BloodPressureCategory = Normal
| Prehypertension
| Hypertension1
| Hypertension2
| HypertensiveCrisis
instance Show BloodPressureCategory where
show Normal = "Normal"
show Prehypertension = "Prehypertension"
show Hypertension1 = "Hypertension (Stage I)"
show Hypertension2 = "Hypertension (Stage II)"
show HypertensiveCrisis = "Hypertensive Crisis"
bloodPressureCategory s d | s >= 180 = HypertensiveCrisis
| d >= 110 = HypertensiveCrisis
| s >= 160 = Hypertension2
| d >= 100 = Hypertension2
| s >= 140 = Hypertension1
| d >= 90 = Hypertension1
| s >= 120 = Prehypertension
| d >= 80 = Prehypertension
| otherwise = Normal
parseArgs = getOpt RequireOrder []
main = do
argv <- getArgs
let cat = case parseArgs argv of
([], (d:s:_), []) -> bloodPressureCategory (read d :: Int) (read s :: Int)
putStrLn $ show cat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment