Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Haskell tutorial - 1

-- Addition Operator
-- https://www.tutorialspoint.com/haskell/haskell_basic_operators.htm
{-main = do 
   let var1 = 2.9 
   let var2 = 3 
   putStrLn "The addition of the two numbers is:" 
   print(var1 + var2) 
-}


-- Sequence / Range Operator
{-main :: IO() 
main = do 
   print [1..10]
-}  


-- Int
{-futureValue :: Float -> Float -> Float -> Float  
futureValue capitalInicial juroAnual numeroDeAnos = capitalInicial*(1+juroAnual/100)**numeroDeAnos
main = print (futureValue 100.0 10.0 1.0) 
-}

-- Factorial
{-fact :: Int -> Int 
fact 0 = 1
fact a = a * fact (a-1)
main = print (fact 3)
-}

-- Factorial on lists
{-
fact :: Int -> Int 
fact 0 = 1
fact a = a * fact (a-1)
map :: (a -> b) -> [a] -> [b]
--map f xs = [f x | x <- xs]
map fact [x1, x2, ..., xn] == [fact x1, fact x2, ..., fact xn]

map fact [x1, x2, ...] == [fact x1, fact x2, ...]
--map fact [1,1,2,3,5,8] 
main = print ( map fact [1..10] ) 
-}

-- Reverse list
{-revr :: [Int] -> [Int]
revr [] = []
revr (h:tl) =  revr tl ++ [h]
main = print (revr [1..20])
-}

-- Max of list
{-maximus :: [Int] -> Int 
maximus [a] = a
maximus (x1:tl) = if x1 > (maximus tl)
                  then x1 
                  else maximus tl
main = print (  maximus [231,9000,22,3] ) 
-}

-- Circle Area
-- URL:  https://www.tutorialspoint.com/haskell/haskell_types_and_type_class.htm
data Area = Circle Float Float Float  
surface :: Area -> Float   
surface (Circle _ _ r) = pi * r ^ 2   
main = print (surface $ Circle 10 20 10 ) 























surface (Circle _ _ r) = pi * r ^ 2   
main = print (surface $ Circle 10 20 10 )
-}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.