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 qualified Data.Foldable as F | |
import Data.Monoid | |
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show) | |
instance Functor Tree where | |
fmap f EmptyTree = EmptyTree | |
fmap f (Node x l r) = Node (f x) (fmap f l) (fmap f r) | |
instance F.Foldable Tree where |
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.Monoid | |
-- class Monoid m where | |
-- mempty :: m | |
-- mappend :: m -> m -> m | |
-- mconcat = foldr mappend mempty | |
-- instance Monoid [a] where | |
-- mepmty = [] | |
-- mappend = (++) |
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 Control.Applicative | |
-- class (Functor f) => Applicative f where | |
-- pure :: a -> f a | |
-- (<*>) :: f (a -> b) -> f a -> f b | |
-- instance Appilcative Maybe where | |
-- pure = Just | |
-- Nothing <*> _ = Nothing | |
-- (Just f) <*> something = fmap f something |
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 |
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 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.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
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 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 |