-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathArithmeticFunction.hs
37 lines (24 loc) · 1.2 KB
/
ArithmeticFunction.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module ArithmeticFunction where
-- |You have two ways to define functions. With and without lambdas
--arithmeticFunction number = number * 100
--The same than the line below
multiplyFunc = (\number -> number * 100):: Int -> Int
sumFunc = (\number -> number + 1000) :: Int -> Int
subtractFunc = (\number -> \amount -> number - amount ) :: Int -> Int -> Int
-- |combining functions
responseValue = sumFunc (multiplyFunc (multiplyFunc 5))
-- | In this function one value it's coming from previous function sumFunction, and the 100
subtractResponse = subtractFunc (sumFunc 200) 100
-- |Running the expression. Using show operator we transform from Int -> String
numericOutput = putStrLn (show responseValue)
-- |print it will print in screen all types that implement show. Since Int is one of them, we're good!
-- |Overload functions in Haskell is done by value types, om this case since we define just one type Num a
-- this it can be whatever type we want, as long as is the same type [a]
overloadSumFunc :: Num a => a -> a -> a
overloadSumFunc = \a -> \b -> a + b
i1 = 6 :: Integer
i2 = 5 :: Integer
overloadIntOutput= overloadSumFunc i1 i2
d1 = 6 :: Double
d2 = 7 :: Double
overloadLongOutput= overloadSumFunc d1 d2