This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Random | |
import Control.Monad (when) | |
main :: IO () | |
main = do | |
gen <- getStdGen | |
askForNumber gen | |
askForNumber :: StdGen -> IO () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Random | |
import Control.Monad (when) | |
main :: IO () | |
main = do | |
gen <- getStdGen | |
askForNumber gen | |
askForNumber :: StdGen -> IO () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Random | |
main :: IO () | |
main = do | |
gen <- getStdGen | |
putStrLn $ take 20 $ randomRs ('a', 'z') gen | |
gen' <- newStdGen | |
putStrLn $ take 20 $ randomRs ('a', 'z') gen' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Random | |
threeCoins :: StdGen -> (Bool, Bool, Bool) | |
threeCoins gen = | |
let (firstCoin, newGen) = random gen | |
(secondCoin, newGen') = random newGen | |
(thirdCoin, _) = random newGen' | |
in (firstCoin, secondCoin, thirdCoin) | |
-- threeCoins (mkStdGen 100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Random | |
threeCoins :: StdGen -> (Bool, Bool, Bool) | |
threeCoins gen = | |
let (firstCoin, newGen) = random gen | |
(secondCoin, newGen') = random newGen | |
(thirdCoin, _) = random newGen' | |
in (firstCoin, secondCoin, thirdCoin) | |
-- threeCoins (mkStdGen 100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment | |
import System.Directory | |
import System.IO | |
import Data.List | |
import Control.Exception | |
dispatch :: String -> [String] -> IO () | |
dispatch "add" = add | |
dispatch "view" = view | |
dispatch "remove" = remove |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment | |
import Data.List | |
main :: IO () | |
main = do | |
args <- getArgs | |
progName <- getProgName | |
putStrLn "The arguments are:" | |
mapM putStrLn args | |
putStrLn "The program name is:" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.IO | |
import System.Directory | |
import Data.List | |
import Control.Exception | |
main :: IO () | |
main = do | |
contents <- readFile "todo.txt" | |
let todoTasks = lines contents | |
numberedTasks = zipWith (\ n line -> show n ++ " - " ++ line) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.IO () | |
main :: IO () | |
main = do | |
todoItem <- getLine | |
appendFile "todo.txt" (todoItem ++ "\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.IO () | |
import Data.Char | |
main :: IO () | |
main = do | |
contents <- readFile "baabaa.txt" | |
writeFile "baabaacaps.txt" (map toUpper contents) |