Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 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