Created
April 24, 2017 11:10
-
-
Save mykhas/04ee89a0b2503ea1fb17071e99398f0d 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 :: Integral a => a -> String | |
lucky 7 = "THAT'S SEVEN!" | |
lucky x = "Not a seven" | |
factorial :: Integral a => a -> a | |
factorial 0 = 1 | |
factorial n = n * factorial (n - 1) | |
addVectors :: Integral a => (a, a) -> (a, a) -> (a, a) | |
addVectors (x1, y1) (x2, y2) = ((x1 + x2), (y1 + y2)) | |
firstOfThree :: Integral a => (a, a, a) -> a | |
firstOfThree (a, _, _) = a | |
secondOfThree :: Integral a => (a, a, a) -> a | |
secondOfThree (_, a, _) = a | |
thirdOfThree :: Integral a => (a, a, a) -> a | |
thirdOfThree (_, _, a) = a | |
head' :: [a] -> a | |
head' [] = error "No way" | |
head' (x:_) = x | |
tell :: Show a => [a] -> String | |
tell [] = "Empty" | |
tell (a:[]) = "One element, " ++ show a | |
tell (a:b:[]) = "Two elements, " ++ show a ++ ", " ++ show b | |
tell all@(a:b:_) = "A lot of elements in " ++ show all ++ ": " ++ show a ++ ", " ++ show b | |
-- sum' :: Num a => [a] -> String | |
-- sum' xs = "Sum is " ++ | |
-- let calculate xs = case xs of [] -> 0 -- як змусити це працювати? | |
-- (x:xs) -> x + sum' xs; | |
-- result = calculate xs | |
-- in show result | |
bmiTell :: RealFloat a => a -> a -> String | |
bmiTell w h | |
| bmi w h < skinny = "Skinny" | |
| bmi w h < ok = "Ok" | |
| bmi w h < fat = "Lil fat" | |
| otherwise = "Fat" | |
where bmi w' h' = w' / h' ^ 2 | |
(skinny, ok, fat) = (18.5, 20, 30) | |
max' :: Ord a => a -> a -> a | |
max' a b | |
| b > a = b | |
| otherwise = a | |
myC :: Ord a => a -> a -> Ordering | |
a `myC` b | |
| a > b = GT | |
| a == b = EQ | |
| otherwise = LT | |
initials :: String -> String -> String -- чому не працює String a => a -> a -> a | |
initials fn ln = [f] ++ " " ++ [l] | |
where (f:_) = fn | |
(l:_) = ln |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment