-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_integralFns.hs
54 lines (39 loc) · 1.63 KB
/
2_integralFns.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- * Native Integral Functions
-- Addition
addition a b = a + b
-- Subtraction
subtraction = 10 - 5 --5
-- Multiplication
multiplication = 10 * 5 --50
-- Div is the division function. This function Returns how many times the first number can be divided by the second one, and gets rid of any remainder.
-- If you want division that produces a Float instead, use "/" instead.
division = 10 `div` 3 --3
-- Mod - mod gets the remainder after a division
modulus = 10 `mod` 3 --1
-- Exponentiation - The '^' operator takes an Integral b and Num a, and returns a Num.
exponentiation = 3 ^ 3 --27
-- (^2) is (\x -> x ^ 2) but (2^) is (\x -> 2 ^ x)
exp1 = (^2) 7
exp2 = (2^) 7
-- Minimum - takes 2 parameters, returns the smaller one
findMin = min 111 222 --111
-- Maximum - takes 2 parameters, returns the larger one
findMax = max 111 222 --222
-- GCD - finds the greatest common integer that both be divided by evenly.
findGCD = gcd 25 310 --5
-- LCM - finds the lowest common integer that both multiply into evenly.
findLCM = lcm 5 11 --55
-- successor - takes a parameter and returns the next number up
findSuccessor = succ 10 --11
-- abs - returns the absolute value, which is positive rather than negative.
getAbs = abs (-10) --10
getAbs' = abs (10) --10
-- negate - returns the opposite of the value given, whether positive or negative.
negateValue = negate (10) --(-10)
negateValue' = negate (-10) --(10)
-- even - test whether an Integer value is even.
isEven = even 10 --True
-- odd - test whether an Integer value is odd.
isOdd = odd 10 --False
-- read - read can be used to convert to an integer if you define the type
convertToInt = read "4" :: Int