comparison Haskell/baby.hs @ 25:8c7e1b34582f

add baby.hs
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Wed, 26 Mar 2014 18:13:52 +0900
parents
children 0f4ccdbaf57f
comparison
equal deleted inserted replaced
24:a8d237e822a8 25:8c7e1b34582f
1 --http://www.haskell.org/hoogle
2
3 {-
4
5 -}
6
7 doubleMe x = x + x
8 doubleUs x y = x * 2 + y * 2
9 doubleSmallNumber x = if x > 100
10 then "x"
11 else "y"
12 masa'koha' x = x
13
14 lucky :: Int -> String
15 lucky 7 = "LUCKY NUMBER SEVEN"
16 lucky x = "Sorry, you're out of luck, pal!"
17
18 factorial :: Int -> Int
19 factorial 0 = 1
20 factorial n = n * factorial (n - 1)
21
22 charName :: Char -> String
23 charName 'a' = "Albert"
24 charName 'b' = "Broseph"
25 charName n = "no match"
26
27 addVectors :: (Double, Double) -> (Double, Double) -> (Double, Double)
28 addVectors a b = (fst a + fst b, snd a + snd b)
29
30 head' :: [a] -> a
31 head' [] = error "Can't call head on an empty list,dummy!"
32 head' (x:_) = x
33
34 firstLetter :: String -> String
35 firstLetter "" = "Empty string"
36 firstLetter all@(x:xs) = "The first letter of " ++ all ++ " is " ++ [x]
37
38 bmiTell :: Double -> Double -> String
39 bmiTell weight height
40 | bmi <= 18.5 = "You're underweight, you emo, you!"
41 | bmi <= 25.0 = "You're supposedly normal.\\ Pffft, I bet you're ugly!"
42 | bmi <= 30.0 = "You're a fat,"
43 | otherwise = "You're a whale, congratulations!"
44 where bmi = weight / height ^ 2
45
46 describeList :: [a] -> String
47 describeList ls = "The list is "
48 ++ case ls of [] -> "empty."
49 [x] -> "a singleton list."
50 xs -> "a longer list."