Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main :: IO()
- main = do
- print $ "hello world"
- print $ "Enter some text right in console!"
- plus :: Int -> Int -> Int
- plus x y = x + y
- minus :: Int -> Int -> Int
- minus x y = x - y
- mult :: Int -> Int -> Int
- mult x y = x * y
- divs :: Int -> Int -> Int
- divs x y = x / y
- divs' :: Int -> Int -> Int
- divs' x y = div x y
- mods :: Int -> Int -> Int
- mods x y = mod x y
- addThree :: Int -> Int -> Int -> Int
- addThree x y z = x + y + z
- factorial :: Int -> Int
- factorial n = product [1..n]
- bigger :: Int -> Int -> Bool
- bigger x y = if x > y then x else y
- lucky :: Int -> String
- lucky 7 = "You got the right number!"
- lucky x = "Sorry, 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 = "Not between 1 and 5"
- factorial' :: Int -> Int
- factorial' 0 = 1
- factorial' 1 = 1
- factorial' n = n * factorial (n-1)
- charName :: Char -> String
- charName 'a' = "Albert"
- charName 'b' = "Broseph"
- charName 'c' = "Cercil"
- addVectors1 :: (Ord a, Num a) => (a,a) -> (a,a) -> (a,a)
- addVectors1 x y = (fst x + fst y, snd x + snd y)
- addVectors2 :: (Ord a, Num a) => (a,a) -> (a,a) -> (a,a)
- addVectors2 (x1,y1) (x2,y2) = (x1+x2,y1+y2)
- first :: (a,b,c) -> a
- first (x, _, _) = x
- second :: (a,b,c) -> b
- second (_, y, _) = y
- third :: (a,b,c) -> c
- third (_, _, z) = z
- head :: [Int] -> Int
- head [] = error "Can't call head on empty list, dummy"
- head (x:_) = x
- -- here we don't care about our first argument
- length :: [Int] -> Int
- length [] = 0
- length (_:xs) = 1 + length xs
- -- but here we are interested in our first argument
- sum :: [Int] -> Int
- sum [] = 0
- sum (x:xs) = x + sum xs
- bmiTell :: (RealFloat a) => a -> String
- bmiTell bmi
- | bmi <= 18.5 = "You are underweight"
- | bmi <= 25.0 = "You are normal weight"
- | bmi <= 30.0 = "You are overweight"
- | otherwise = "If you contunue to eat, you are gonna die"
- bmiTell1 :: (RealFloat a) => a -> a -> String
- bmiTell1 weight height
- | weight / height ^ 2 <= 18.5 = "You are underweight"
- | weight / height ^ 2 <= 25.0 = "You are normal weight"
- | weight / height ^ 2 <= 30.0 = "You are overweight"
- | otherwise = "You are a whale, congratulations"
- bmiTell2 :: (RealFloat a) => a -> a -> String
- bmiTell2 weight height
- | bmi <= 18.5 = "You are underweight"
- | bmi <= 25.0 = "You are normal weight"
- | bmi <= 30.0 = "You are overweight"
- | otherwise = "You are a whale, congratulations"
- where
- bmi = weight / height ^ 2
- bmiTell3 :: (RealFloat a) => a -> a -> String
- bmiTell3 weight height
- | bmi <= skinny = "You are underweight"
- | bmi <= normal = "You are normal weight"
- | bmi <= overweight = "You are overweight"
- | otherwise = "You are a whale, congratulations"
- max1 :: Int -> Int -> Int
- max1 a b
- | a > b = a
- | otherwise = b
- min1 :: Int -> Int -> Int
- min1 a b
- | a > b = b
- | otherwise = a
- maxThree :: Int -> Int -> Int -> Int
- maxThree a b c = if (a > b) && (a > c) then a else if (b > a) && (b > c) then b else c
- maxThree1 :: Int -> Int -> Int -> Int
- maxThree1 a b c
- | (a > b) && (a > c) = a
- | (b > a) && (b > c) = b
- | otherwise = c
- myCompare :: Int -> Int -> String
- myCompare a b
- | a > b = "GT"
- | a < b = "LT"
- | otherwise = "EQ"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement