CSC/ECE 517 Fall 2010/ch1 1e bb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
Line 5: Line 5:
A more practical benefit of functional programming is that it forces you to break apart your problem into small pieces. Small functions are also easier to read and to check for errors, thus debugging is easier.
A more practical benefit of functional programming is that it forces you to break apart your problem into small pieces. Small functions are also easier to read and to check for errors, thus debugging is easier.
Functional Programming discourages the use of variables.
Functional Programming discourages the use of variables.
fun factorial (0 : int) : int = 1
  | factorial (n : int) : int = n * factorial (n-1)

Revision as of 18:23, 8 September 2010

Functional Programming

Functional programming treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes on the application of functions, also called applicative programming. Functional programming decomposes a problem into a set of functions. Ideally, functions only take inputs and produce outputs, and don't have any internal state that affects the output produced for a given input. Well-known functional languages include the ML family (Standard ML, OCaml, and other variants) and Haskell. In a functional program, input flows through a set of functions. Each function operates on its input and produces some output A more practical benefit of functional programming is that it forces you to break apart your problem into small pieces. Small functions are also easier to read and to check for errors, thus debugging is easier. Functional Programming discourages the use of variables.


fun factorial (0 : int) : int = 1

 | factorial (n : int) : int = n * factorial (n-1)