Hi All.. Now i would explain about Nesting In F# programing system
Function and variable definitions can be structured hierarchically within an F# program, allowing some definitions to be globally visible, others to be defined separately in distinct portions of the hierarchy, others to be visible only within a single branch of the hierarchy and others to be refined, specialising them within the hierarchy. Compared to writing a program as a flat list of function and variable definitions, structuring a program into a hierarchy of definitions allows the number of dependencies within the program to be managed as the size and complexity of the programs grows.
This is achieved most simply by nesting definitions. Thus, nesting is the simplest approach to the structuring of programss. For example, the ipow3 function defined in the previous chapter contains a nested definition of a function sqr:
Function and variable definitions can be structured hierarchically within an F# program, allowing some definitions to be globally visible, others to be defined separately in distinct portions of the hierarchy, others to be visible only within a single branch of the hierarchy and others to be refined, specialising them within the hierarchy. Compared to writing a program as a flat list of function and variable definitions, structuring a program into a hierarchy of definitions allows the number of dependencies within the program to be managed as the size and complexity of the programs grows.
This is achieved most simply by nesting definitions. Thus, nesting is the simplest approach to the structuring of programss. For example, the ipow3 function defined in the previous chapter contains a nested definition of a function sqr:
> let ipow3 x =
let sqr x = x * x
x * sqr x;;
val ipow3 : int -> int
The nested function sqr is only “visible” within the remainder of the definition of ipow3 and cannot be used outside this function. This capability is particularly useful when part of a function is best factored out into an auxiliary function that has no meaning or use outside its parent function. Nesting an auxiliary function can improve clarity without polluting the external namespace, e.g. with a definition ipow3-aux. Nesting can be more productively exploited when combined with the factoring of subexpressions, functions and higher-order functions.
Comments