Feng Liu
Feng Liu

Reputation: 63

What does the type "string * string" mean in F#?

Tried searching everywhere. Looking at https://github.com/fsharp/FAKE/blob/master/src/app/Fake.IIS/IISHelper.fs#L64 with parameter string * string. Tried to instantiate in F# code and received error FS0010: Incomp lete structured construct at or before this point in expression.

What in the world is this and how does on instantiate this?

Upvotes: 1

Views: 532

Answers (1)

string*string is a pair of two strings and is roughly equal to Tuple<string, string>. string*int*decimal is then roughly equal to Tuple<string, int, decimal>.

You create an instance of string*string using the following expression "first", "second". An instance of string*int*decimal is created like so "1", 2, 3.0M.

For more information on tuples see: https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/tuples

The rationale for this notation is easier to see if you consider that F# has an algebra for creating types; * create tuples and | creates unions.

// Tree is roughly equal to having an interface Tree 
//  with three implementations Empty, Leaf and Fork
type Tree<'T> =
  | Empty
  | Leaf  of 'T
  | Fork  of Tree<'T>*Tree<'T>

Having an algebra for type creation is very powerful as Scott Wlaschin demonstrates: https://fsharpforfunandprofit.com/ddd/

Upvotes: 6

Related Questions