Friday, January 21, 2011

Studying F# : Map

I wrote this post : phosphorescence: Studying F# : Dictionary (a.k.a. Hash or Map). But it is incorrect. Map is there! Map must be created by using List, Tuple and the function Map.ofList.

Microsoft (R) F# 2.0 Interactive build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> let map_1 = Map.ofList[ (1, "one"); (2, "two"); (3, "three"); (4, "four") ];;

val map_1 : Map<int,string> =
  map [(1, "one"); (2, "two"); (3, "three"); (4, "four")]

2 comments:

Jon Harrop said...

You can just do Map[1, "one"; 2, "two"; 3, "three"; 4, "four"]

Youhei Kondou said...

Thanks a lot

Post a Comment