Created
September 21, 2015 10:43
-
-
Save motokiee/55a1685ee9d7da677a8c to your computer and use it in GitHub Desktop.
This file contains 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
lucky :: Int -> String | |
lucky 7 = "LUCKY NUMBER SEVEN!!" | |
lucky x = "SORRY," ++ show x ++ " YOU'RE OUT OF LUCK!!" | |
sayMe :: Int -> String | |
sayMe 1 = "One" | |
sayMe 2 = "Two" | |
sayMe 3 = "Three" | |
sayMe 4 = "Four" | |
sayMe 5 = "Five" | |
sayMe x = show x ++ "is" ++ "not between 1 and 5" | |
addVectors :: (Double, Double) -> (Double, Double) -> (Double, Double) | |
addVectors (x1, y1) (x2, y2) = (x1+x2, y1+y2) | |
first :: (a,b,c) -> a | |
first (a,_,_) = a | |
second :: (a,b,c) -> b | |
second (_,b,_) = b | |
third :: (a,b,c) -> c | |
third (_,_,c) = c | |
factorial :: Int -> Int | |
factorial 0 = 1 | |
factorial n = n * factorial (n-1) | |
head' :: [a] -> a | |
head' [] = error "Can't call head on an empty list" | |
head' (x:_) = x | |
tell :: (Show a) => [a] -> String | |
tell [] = "The list is empty." | |
tell (x:[]) = "The list has one element." ++ show x | |
tell (x:y:[]) = "The list has two elements: " ++ show x ++ " and " ++ show y | |
tell (x:y:_) = "The list is long. The first two elements are: " ++ show x ++ " and " ++ show y | |
firstLetter :: String -> String | |
firstLetter "" = "Empty String" | |
firstLetter all@(x:xs) = "The first letter of " ++ all ++ " is " ++ [x] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment