wmi-parprog/08_Haskell/ex1-tutorial.hs

132 lines
3.2 KiB
Haskell
Raw Permalink Normal View History

2024-05-13 14:30:32 +02:00
#!/usr/bin/env runhaskell
2024-06-03 15:32:03 +02:00
-- main = do
-- print [1..10]
2024-05-13 14:30:32 +02:00
2024-06-03 10:14:42 +02:00
2024-05-13 14:30:32 +02:00
-- fType :: Int -> Int -> Int
-- fType x y = x*x + y*y
-- main = print (fType 2 4)
2024-06-03 10:14:42 +02:00
-- fType :: Integer -> Integer -> Integer
-- fType x y = x*x + y*y
-- main = print (fType 212124454 44545454454554545454454454545445446382473284328943648726487623784623786478235472678654358436857348573947854454545445455454545445445454544544638247328432894364872648762378462378647823547267865435843685734857394785)
2024-05-13 14:30:32 +02:00
2024-06-03 10:14:42 +02:00
-- fact :: Integer -> Integer
-- fact n | n == 0 = 1
2024-06-03 15:32:03 +02:00
-- | n /= 0 = n * fact (n-1)
2024-06-03 10:14:42 +02:00
-- main = do
2024-05-13 14:30:32 +02:00
-- putStrLn "The factorial of 5 is:"
-- print (fact 5)
-- roots :: (Float, Float, Float) -> (Float, Float)
-- roots (a,b,c) = (x1, x2) where
-- x1 = e + sqrt d / (2 * a)
-- x2 = e - sqrt d / (2 * a)
-- d = b * b - 4 * a * c
-- e = - b / (2 * a)
-- main = do
-- putStrLn "The roots of our Polynomial equation are:"
-- print (roots(1,-8,6))
-- import Data.Char
-- import Prelude hiding (map)
-- map :: (a -> b) -> [a] -> [b]
-- map _ [] = []
-- map func (x : abc) = func x : map func abc
-- main = print $ map toUpper "tutorialspoint.com"
-- main = do
-- putStrLn "The successor of 4 is:"
-- print ((\x -> x + 1) 4)
-- main = do
-- let x = [1..10]
-- putStrLn "Our list is:"
-- print (x)
-- putStrLn "The first element of the list is:"
-- print (head x)
-- putStrLn "The tail of our list is:"
-- print (tail x)
-- putStrLn "The last element of our list is:"
-- print (last x)
-- putStrLn "Our list without the last entry:"
-- print (init x)
-- putStrLn "Is our list empty?"
-- print (null x)
-- putStrLn "The list in Reverse Order is:"
-- print (reverse x)
-- putStrLn "The length of this list is:"
-- print (length x)
-- print(take 5 ([1 .. 10]))
-- print(drop 5 ([1 .. 10]))
-- putStrLn "The maximum value element of the list is:"
-- print (maximum x)
-- putStrLn "The minimum value element of the list is:"
-- print (minimum x)
-- putStrLn "The summation of the list elements is:"
-- print (sum x)
-- putStrLn "The multiplication of the list elements is:"
-- print (product x)
-- putStrLn "Does it contain 786?"
-- print (elem 9 (x))
-- doubleListA [] = []
-- doubleListA (x:xs) = 2*x : doubleListA xs
-- tripleListB [] = []
-- tripleListB (x:xs) = 3*x : tripleListB xs
-- multList n [] = []
-- multList n (x:xs) = n*x : multList n xs
-- tripleList = multList 3
-- doubleList = multList 2
-- main = do
-- let x = [1..10]
-- putStrLn "Our list is:"
-- print (x)
2024-06-03 10:14:42 +02:00
-- print (doubleListA x)
2024-05-13 14:30:32 +02:00
-- print (doubleList x)
2024-06-03 15:32:03 +02:00
eveno :: Int -> Bool
noto :: Bool -> String
2024-05-13 14:30:32 +02:00
2024-06-03 15:32:03 +02:00
eveno x = if x `rem` 2 == 0
then True
else False
noto x = if x == True
then "This is an even Number"
else "This is an ODD number"
2024-05-13 14:30:32 +02:00
2024-06-03 15:32:03 +02:00
main = do
putStrLn "Example of Haskell Function composition"
print ((noto.eveno)(16))
2024-05-13 14:30:32 +02:00
-- import Data.List
-- main = do
-- putStrLn("Different methods of List Module")
-- print(intersperse '.' "Tutorialspoint.com")
-- print(intercalate " " ["Lets","Start","with","Haskell"])
-- print(splitAt 7 "HaskellTutorial")
-- print (sort [8,5,3,2,1,6,4,2])