Content deleted Content added
Wavelength (talk | contribs) "kind of like" (noun and preposition and preposition) —> "somewhat like" (adverb and preposition)—wikt:kind of—wikt:somewhat |
No edit summary |
||
Line 252:
In both cases, any Erlang term can be used as the key. Variations include the <code>orddict</code> module, implementing ordered dictionaries, and <code>gb_trees</code>, implementing general balanced trees.
===F#===
[[FSharp|F#]] constructs maps from lists, sequences or arrays of [[tuple]]s, using functions provided by the Map module. F# represents a tuple as two or more elements separated by a comma, and a list as a sequence of elements enclosed in square brackets, separated by semi-colons.
<source lang=fsharp>
let numbers = [ "Sally Smart", "555-9999";
"John Doe", "555-1212";
"J. Random Hacker", "555-1337" ] |> Map.ofList
</source>
Values can be looked up via one of the <code>Map object</code> functions, such as <code>TryFind</code>. This returns an [[option type]] with a value of <code>Some</code>, for a successful lookup, or <code>None</code>, for an unsuccessful one. [[Pattern matching]] can then be used to extract the raw value, or a default, from the result.
<source lang=fsharp>
let sallyNumber = match numbers.TryFind("Sally Smart") with
| Some(number) -> number
| None -> "n/a"
</source>
In this example, the <code>sallyNumber</code> value will now contain the string <code>"555-9999"</code>.
Because F# is a .NET language, it also has access to all of the features of the [[.NET Framework]], including the <code>Dictionary</code> objects and <code>HashTable</code> objects that are used for the same purpose in both C# and Visual Basic. These objects may be preferred when writing code that is intended by be linked to from other languages on the .NET framework.
===FoxPro===
|