### changeset 25:8c7e1b34582f

author Masataka Kohagura Wed, 26 Mar 2014 18:13:52 +0900 a8d237e822a8 0f4ccdbaf57f Haskell/baby.hs 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
```--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Haskell/baby.hs	Wed Mar 26 18:13:52 2014 +0900
@@ -0,0 +1,50 @@
+
+{-
+
+-}
+
+doubleMe x = x + x
+doubleUs x y = x * 2 + y * 2
+doubleSmallNumber x = if x > 100
+                    then "x"
+                    else "y"
+masa'koha' x = x
+
+lucky :: Int -> String
+lucky 7 = "LUCKY NUMBER SEVEN"
+lucky x = "Sorry, you're out of luck, pal!"
+
+factorial :: Int -> Int
+factorial 0 = 1
+factorial n = n * factorial (n - 1)
+
+charName :: Char -> String
+charName 'a' = "Albert"
+charName 'b' = "Broseph"
+charName n = "no match"
+
+addVectors :: (Double, Double) -> (Double, Double) -> (Double, Double)
+addVectors a b = (fst a + fst b, snd a + snd b)
+
+
+firstLetter :: String -> String
+firstLetter "" = "Empty string"
+firstLetter all@(x:xs) = "The first letter of " ++ all ++ " is " ++ [x]
+
+bmiTell :: Double -> Double -> String
+bmiTell weight height
+    | bmi <= 18.5 =  "You're underweight, you emo, you!"
+    | bmi <= 25.0 =  "You're supposedly normal.\\ Pffft, I bet you're ugly!"
+    | bmi <= 30.0 =  "You're a fat,"
+    | otherwise =  "You're a whale, congratulations!"
+    where bmi = weight / height ^ 2
+
+describeList :: [a] -> String
+describeList ls = "The list is "
+                  ++ case ls of [] -> "empty."
+                                [x] -> "a singleton list."
+                                xs -> "a longer list."```