Multiple Return Values in F#
F# has built-in support for multiple return values through tuples. This feature is used often in idiomatic F#, for example to return both result and error values from a function.
The int * int
in this function signature shows that the function returns a tuple of 2 int
s.
Here’s how we use the function and handle its return values:
To run the program, you would typically save it as a .fs
file and use the F# compiler or an F# interactive environment.
F# provides a concise and type-safe way to work with multiple return values through its tuple system and pattern matching capabilities. This allows for expressive and readable code when dealing with functions that need to return more than one value.
Accepting a variable number of arguments is another feature available in F#; we’ll look at this in a future example.