Skip to content

Instantly share code, notes, and snippets.

View MiyamonY's full-sized avatar
🏠
Working from home

MiyamonY

🏠
Working from home
View GitHub Profile
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'
import System.Random
import Control.Monad (when)
main :: IO ()
main = do
gen <- getStdGen
askForNumber gen
askForNumber :: StdGen -> IO ()
import System.Random
import Control.Monad (when)
main :: IO ()
main = do
gen <- getStdGen
askForNumber gen
askForNumber :: StdGen -> IO ()
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
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
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,
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,
-- 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"
import Data.Char
import Data.List
main :: IO ()
main = do line <- fmap (intersperse '-' . reverse . map toUpper) getLine
putStrLn line
-- instance Functor ((->) r) where
-- fmap f g = (\ x -> f (g x))
-- instance Functor ((->) r) where
-- fmap = (.)
-- functor laws
-- first law
-- isntance Fucntor Maybe where