Skip to content

Fork synch #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Homework/Homework01/Homework01.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,31 @@
-- Question 1
-- Write a multiline comment below.

{-
This
is
a
multiline
comment
-}

-- Question 2
-- Define a function that takes a value and multiplies it by 3.

multiplyBy3 x = x * 3

-- Question 3
-- Define a function that calculates the area of a circle.

circleArea r = pi * r^2

-- Question 4
-- Define a function that calculates the volume of a cylinder by composing the previous function together with the height of the cylinder.

cilinderArea r h = circleArea r * h

-- Question 5
-- Define a function that takes the height and radius of a cylinder and checks if the volume is greater than or equal to 42.

checkVolume r h = cilinderArea r h >=42

31 changes: 26 additions & 5 deletions Homework/Homework02/Homework02.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,52 @@
-- Add the type signatures for the functions below and then remove the comments and try to compile.
-- (Use the types presented in the lecture.)

-- f1 x y z = x ** (y/z)
f1 :: Double -> Double -> Double -> Double
f1 x y z = x ** (y/z)

-- f2 x y z = sqrt (x/y - z)
f2 :: Double -> Double -> Double -> Double
f2 x y z = sqrt (x/y - z)

-- f3 x y = [x == True] ++ [y]
f3 :: Char -> Double -> String -> String
f3 x y z = x:((show y) ++ z)

-- f4 x y z = x == (y ++ z)
f4 :: Double -> Double -> Bool -> [Bool]
f4 x y z = [x > y] ++ [z]

f5 :: String -> String -> String -> Bool
f5 x y z = x == (y ++ z)

-- Question 2
-- Are really all variables in Haskell immutable? Try googling for the answer.
-- There are some Monad type that allow to deal with mutable variable within a context by keeping
-- at the same time a functional style.


-- Question 3
-- Why should we define type signatures of functions? How can they help you? How can they help others?

-- Even tough is not modantory, we should always add functions signatures in order to make the code more
-- readable and so more maintanable also from other devs.

-- Question 4
-- Why should you define type signatures for variables? How can they help you?



-- Question 5
-- Are there any functions in Haskell that let you transform one type to the other? Try googling for the answer.
-- Yes, for example the show show function allow to transform/cast any type to a [char]


-- Question 6

-- How would you write the prod function from our lesson so that it works for Int and Double? Does the code compile?
-- We can use the Num type class constraint on the function signature.
-- Num a => a -> a -> a
-- The num class contain the implementtion of the inline fucntion * that can be applied to
-- any value representing a number.


-- Question 7
-- Can you also define in Haskell list of lists? Did we showed any example of that? How would you access the inner
-- most elements?
-- Yes, for example a list of string [String] is equel to [[Char]]. We can access by !! indexFirstList !! indexSecondList