File: Functions.fs

package info (click to toggle)
mono 6.12.0.199%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,192 kB
  • sloc: cs: 11,181,844; xml: 2,850,076; ansic: 689,413; cpp: 123,344; perl: 59,361; javascript: 30,841; asm: 21,845; makefile: 19,951; sh: 15,030; python: 4,771; pascal: 925; sql: 859; sed: 16; php: 1
file content (35 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download | duplicates (7)
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
module Functions

// You define functions by using the let keyword, or, if the function is recursive, the let rec keyword combination.+
let rec fib n = if n < 2 then 1 else fib (n - 1) + fib (n - 2)

let rec public publicLet n = if n < 2 then 1 else fib (n - 1) + fib (n - 2)

// Functions in F# can be composed from other functions. 
// The composition of two functions function1 and function2 is another function that represents the application of function1 followed the application of function2:
let function1 x = x + 1
let function2 x2 = x2 * 2
let function3 (x3) = x3 * 2
let function4 x4 y4 = x4 + y4
let function5 (x5, y5) = x5 + y5
let function6 (x6, y6) = ()
let function7 x7 (y7, z7) = ()
let function8 x8 y8 z8 = ()
let function9 (x9, y9) (z9, a9) = ()
let function10<'a> (x, y) (z, a) = ()
let function11<'a> (x, y, z) (a, b) = ()
let function12<'a> x (a, b, c, d, e) = ()
let function13<'a> (a:'a) = ()

let get_function x = x + 1

let h = function1 >> function2
let result5 = h 100

//Pipelining enables function calls to be chained together as successive operations. Pipelining works as follows:
let result = 100 |> function1 |> function2

type TestFunction() =
    member this.f13 : 'a -> unit = function13
    // member this.f13<'a> : 'a -> unit = function13 // Error	FS0671	A property cannot have explicit type parameters. Consider using a method instead.