Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue