Higher-order functions

Higher order functions

Higher order functions return functions as a result

  • Higher order functions also take other functions as parameters

We can write:

Function types

Type A => B is the type of a function that takes an argument of type A and returns a result of type B

Anonymous functions

Anonymous functions are functions without names

(x: Int, y: Int) is the parameter of the function, and x + y is its body.

The type of the parameter can be omitted

Examples

Ex1: Write a function that takes the product of all the integers on a given interval

Ex2: Write a function that takes the product of the factorials of all the integers  on a given interval

Ex3: Write a general function which generalizes both sum and product

 

You May Also Like

About the Author: Phuong Ta Thi Thao

Leave a Reply

avatar
  Subscribe  
Notify of