The first line you posted:

1
let test m k = m.[k] * 1.0

Gives me the following warning and errors.

file1.fs(1,15): warning FS0044: This construct is deprecated. This warning is due to a lookup of the form 'obj.[idx]' where the type of 'obj' is indeterminate based on the information available at the point where the expression occurs. Consider adding further type constraints.
file1.fs(1,15): error FS0191: Could not resolve the ambiguity inherent in the use of the overloaded operator 'get_Item' at or near this program point. Consider using type annotations to resolve the ambiguity.
file1.fs(1,15): error FS0071: Type constraint mismatch when applying the default type 'obj' for a type inference variable. The type 'obj' does not support any operators named 'get_Item' Consider adding further type constraints.

A bit verbose but basically saying you need to use a type constrant. The other two lines you posted, where you apply the required type constraint:

1
2
let test (m: Map<_,float>) k = m.[k] * 1.0
let test (m: Map<_,_>) k = m.[k] * 1.0

Both compile with out any issue with version 1.9.4.15, which version are you using?

Cheers,
Rob

By on 6/16/2008 12:29 AM ()

Thanks for the reply.

It seems I was mistaken in believing that I needed a "open Map", which causes the warning, e.g.:

1
2
3
open Map

let test (m: Map<_,float>) k = m.[k] * 1.0

This is in F# Interactive, 1.9.4.17.

By on 6/16/2008 5:27 PM ()

Hi Gavin,

Yes although you can open modules it's generally best not to, you should only really open namespaces. For example you could write:

1
2
3
4
5
open List

...

map (fun x -> x + 1) myList

And it becomes very difficult to tell what map is espically as there's a map function in the Seq and Array modules as well.

Cheers,
Rob

By on 6/17/2008 12:39 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