Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Call-a-function/F-Sharp/call-a-function.fs
Normal file
43
Task/Call-a-function/F-Sharp/call-a-function.fs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// No arguments
|
||||
noArgs()
|
||||
|
||||
// Fixed number of arguments
|
||||
oneArg x
|
||||
|
||||
// Optional arguments
|
||||
// In a normal function:
|
||||
optionalArgs <| Some(5) <| None
|
||||
// In a function taking a tuple:
|
||||
optionalArgsInTuple(Some(5), None)
|
||||
// In a function in a type:
|
||||
foo.optionalArgs 5;;
|
||||
// However, if you want to pass more than one paramter, the arguments must be
|
||||
// passed in a tuple:
|
||||
foo.optionalArgs(5, 6)
|
||||
|
||||
// Function with a variable number of arguments
|
||||
variableArgs 5 6 7 // etc...
|
||||
|
||||
// Named arguments can only be used in type methods taking a tuple. The
|
||||
// arguments can appear in any order.
|
||||
foo.namedArgs(x = 5, y = 6)
|
||||
|
||||
// Using a function in a statement
|
||||
for i = 0 to someFunc() do
|
||||
printfn "Something"
|
||||
|
||||
// Using a function in a first-class context
|
||||
funcArgs someFunc
|
||||
|
||||
// Obtaining a return value
|
||||
let x = someFunc()
|
||||
|
||||
// Built-in functions: do functions like (+) or (-) count?
|
||||
|
||||
// Parameters are normally passed by value (as shown in the previous examples),
|
||||
// but they can be passed by reference.
|
||||
// Passing by reference:
|
||||
refArgs &mutableVal
|
||||
|
||||
// Partial application example
|
||||
let add2 = (+) 2
|
||||
Loading…
Add table
Add a link
Reference in a new issue