changeset 25:8c7e1b34582f

add baby.hs
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Wed, 26 Mar 2014 18:13:52 +0900
parents a8d237e822a8
children 0f4ccdbaf57f
files Haskell/baby.hs
diffstat 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 @@
+--http://www.haskell.org/hoogle
+
+{-
+
+-}
+
+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)
+
+head' :: [a] -> a
+head' [] = error "Can't call head on an empty list,dummy!"
+head' (x:_) = x
+
+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."