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 | |
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.Environment | |
import System.Directory | |
import System.IO | |
import Control.Exception | |
import qualified Data.ByteString.Lazy as B | |
main :: IO () | |
main = do | |
(fileName : fileName2: _) <- getArgs | |
copy fileName fileName2 |
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
solveRPN :: String -> Double | |
solveRPN = head . foldl foldingFunction [] . words | |
where foldingFunction (x:y:ys) "*" = (y * x) : ys | |
foldingFunction (x:y:ys) "+" = (y + x) : ys | |
foldingFunction (x:y:ys) "-" = (y - x) : ys | |
foldingFunction (x:y:ys) "/" = (y / x) : ys | |
foldingFunction (x:y:ys) "^" = (y ** x) : ys | |
foldingFunction (x:xs) "ln" = log x : xs | |
foldingFunction xs "sum" = [sum xs] | |
foldingFunction xs numberString = read numberString : xs |
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 Data.List | |
data Section = Section {getA :: Int, getB :: Int, getC :: Int } | |
deriving (Show) | |
type RoadSystem = [Section] | |
heathrowToLondon :: RoadSystem | |
heathrowToLondon = [Section 50 10 30, | |
Section 5 90 20, |
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 Data.List | |
data Section = Section {getA :: Int, getB :: Int, getC :: Int } | |
deriving (Show) | |
type RoadSystem = [Section] | |
heathrowToLondon :: RoadSystem | |
heathrowToLondon = [Section 50 10 30, | |
Section 5 90 20, |
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
-- instance Functor IO where | |
-- fmap f action = do | |
-- result <- action | |
-- return (f result) | |
main :: IO () | |
-- main = do line <- getLine | |
-- let line' = reverse line | |
-- putStrLn $ "You said " ++ line' ++ " backwards!" | |
-- putStrLn $ "Yes, you said " ++ line' ++ " backwards" |
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 Data.Char | |
import Data.List | |
main :: IO () | |
main = do line <- fmap (intersperse '-' . reverse . map toUpper) getLine | |
putStrLn 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
-- instance Functor ((->) r) where | |
-- fmap f g = (\ x -> f (g x)) | |
-- instance Functor ((->) r) where | |
-- fmap = (.) | |
-- functor laws | |
-- first law | |
-- isntance Fucntor Maybe where |