Functions as first class values and numerical method for simple integral calculation
In functional programming, functions can be assigned to variables, passed to other functions as parameters, and returned as values from other functions. Such functions are known as First Class Functions. A higher-order function is a function which takes a function as argument or returns a function. Examples: object HOFuncs extends App { def sum(f: Int => Int, a: Int, b: Int):Int = { if (a > b) 0 else f(a)+sum(f,a+1,b) } def sq(x: Int) : Int = x*x def cube(x: Int) : Int = x*x*x def usrFun(x: Int) :Int = x + x*x println("sum(sq,1,3) = "+sum(sq,1,3)) // 1*1 + 2*2 + 3*3 = 1+4+9 = 14 println("sum(cube,1,3) = "+sum(cube,1,3)) // 1+8+27 = 36 println("sum(usrFun,1,3) = "+sum(usrFun,1,3)) // (1+1*1)+(2+2*2)+(3+3*3) = 2 + 6 + 12 = 20 } Output: sum(sq,1,3) = 14 sum(cube,1,3) = 36 sum(usrFun,1,3) = 20 Now I am going calculate integral of function of one variable with mathematics and with scala. Als...