2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,16 @@
import System.Exit (die)
import Control.Monad (mapM_)
main = do
putStrLn "Please enter temperature in kelvin: "
input <- getLine
let kelvin = read input
if kelvin < 0.0
then die "Temp cannot be negative"
else mapM_ putStrLn $ convert kelvin
convert :: Double -> [String]
convert n = zipWith (++) labels nums
where labels = ["kelvin: ", "celcius: ", "farenheit: ", "rankine: "]
conversions = [id, subtract 273, subtract 459.67 . (1.8 *), (*1.8)]
nums = (show . ($n)) <$> conversions

View file

@ -0,0 +1,24 @@
{-# LANGUAGE LambdaCase #-}
import System.Exit (die)
import Control.Monad (mapM_)
import Control.Error.Safe (tryAssert, tryRead)
import Control.Monad.Trans (liftIO)
import Control.Monad.Trans.Except
main = putStrLn "Please enter temperature in kelvin: " >>
runExceptT getTemp >>=
\case Right x -> mapM_ putStrLn $ convert x
Left err -> die err
convert :: Double -> [String]
convert n = zipWith (++) labels nums
where labels = ["kelvin: ", "celcius: ", "farenheit: ", "rankine: "]
conversions = [id, subtract 273, subtract 459.67 . (1.8 *), (1.8 *)]
nums = (show . ($ n)) <$> conversions
getTemp :: ExceptT String IO Double
getTemp = do
t <- liftIO getLine >>= tryRead "Could not read temp"
tryAssert "Temp cannot be negative" (t>=0)
return t

View file

@ -1,18 +0,0 @@
main = do
putStrLn "Please enter temperature in kelvin: "
input <- getLine
let kelvin = read input :: Double
if
kelvin < 0.0
then
putStrLn "error"
else
let
celsius = kelvin - 273.15
fahrenheit = kelvin * 1.8 - 459.67
rankine = kelvin * 1.8
in do
putStrLn ("kelvin: " ++ show kelvin)
putStrLn ("celsius: " ++ show celsius)
putStrLn ("fahrenheit: " ++ show fahrenheit)
putStrLn ("rankine: " ++ show rankine)