The code is valid with compilation, because type inference can use the whole file to infer the exact type. In interactive mode, type inference can only use the current phrase (and old ones).

First solution (the two lines are sent in the same time):

1
2
3
> let omDestinationTable = Hashtbl.create 30
let _ = Hashtbl.add omDestinationTable "foo" 2;;
val omDestinationTable : HashMultiMap<string,int>

Second solution (add type annotations):

1
let omDestinationTable: (int, string) Hashtbl.t = Hashtbl.create 30;;

or:

1
let omDestinationTable: HashMultiMap<string,int> = Hashtbl.create 30;;

Laurent.

By on 5/30/2007 9:18 AM ()

By the way HashMultiMap (the .NET type) and HashTable (this comes from OCaml) are the same types. From hashtbl.fs:

1
2
3
4
5
6
type HashTable<'key,'a> = Microsoft.FSharp.Collections.HashMultiMap<'key,'a>


type ('key,'a) t = Microsoft.FSharp.Collections.HashMultiMap<'key,'a>

I suggest you to use HashTable. It allows you to call .NET methods as well as functions defined in the fslib.

Unfortunately, Maps don't offer constant access times, because it's implemented using a binary tree (at least, this is how it's defined in OCaml, I believe it's similar in .NET). So most operations are logarithmic (in the size of the map). If performances are very important, you can make some tests. If your map isn't huge, it may be as fast as the hashtable.

I usually prefer maps, because there are no side-effects.

Laurent.

By on 5/30/2007 9:49 AM ()

Thanks for the information, from my initial tests Map seems to be as fast as hashtable, building it is actually faster.

Parnell

By on 5/30/2007 11:42 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper