Skip to content

Instantly share code, notes, and snippets.

@roman
Created September 26, 2013 02:32
Show Gist options
  • Save roman/6709092 to your computer and use it in GitHub Desktop.
Save roman/6709092 to your computer and use it in GitHub Desktop.
Session Haskellñol
module Main where
main :: IO ()
main = putStrLn "Hello World"
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
fib' n
| n == 0 = 0
| n == 1 = 1
| otherwise = fib (n - 1) + fib (n - 2)
first :: [a] -> a
first (a:as) = a
rest :: [a] -> [a]
rest (a:as) = as
-- mergeSort :: (Ord a, Eq a) => [a] -> [a]
-- mergeSort [] = []
-- mergeSort (x:xs) = mergeSort ls ++ [x] ++ mergeSort gs
-- where
-- ls = filter (< x) xs
-- gs = filter (>= x) xs
-- data Category = Vegetables | Proteins | Dairy
-- data TrainedCategory = TrainedCategory Category [String]
-- data Profesor = Preparador
-- | Contratado
-- | TiempoCompleto
-- deriving (Show)
type Salario = Int
data Profesor = Preparador Salario
| Contratado Salario
| TiempoCompleto Salario
deriving (Show)
esPreparador :: Profesor -> Bool
esPreparador (Preparador _) = True
esPreparador _ = False
modPreparadorOContratado :: (Salario -> Salario) -> Profesor -> Profesor
modPreparadorOContratado modFn (Preparador salario) = Preparador (modFn salario)
modPreparadorOContratado modFn (Contratado salario) = Contratado (modFn salario)
modPreparadorOContratado _ a = a
blah = map (modPreparadorOContratado (+5)) . filter esPreparador
-- power :: String -> Int -> Int
-- power a b = a ^ b
add :: Int -> Int -> Int
add a b = a + b
-- incPower2 a = power (add 1 a) 2
-- incPower2' = flip power 2 . add 1
inc :: Int -> Int
inc = add 1
{- Pure Functional, Lazy -}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment