there are type annotations on Map up there that are eaten by the forum software.

By on 5/7/2010 3:00 PM ()

If you want to add to the Map module, then just say module Map = and define the function with a let.

If you want to add an instance method to the Map<Key,Value> type, then use the syntax you're using, but say <'Key,'Value> after Collections.Map.

EDIT:

Whoops, I see you tried the type parameters but they got cut from your post. I think you're missing a constraint, let me go try it...

Here you go:

1
2
3
4
5
6
7
8
9
 

type Microsoft.FSharp.Collections.Map<'Key,'Value when 'Key : comparison> with
    member this.TryFindDefault (key:'Key) (zero:'Value) =
        match this.TryFind(key) with
        | None -> zero
        | Some(value) -> value

(reply with the 'quote' button to see how to post/format code)

By on 5/7/2010 3:00 PM ()

Brilliant, that did it ... almost.

I think I needed:

1
2
3
4
5
6
type Microsoft.FSharp.Collections.Map<'Key,'Value when 'Key : comparison> with

    member this.TryFindDefault (key : 'Key, zero : 'Value) =
        match this.TryFind(key) with
        | None -> zero
        | Some(value) -> value

with the parameters for TryFindDefault defined just slightly differently as above.

How was I know know about the needed "when 'Key : comparison" portion of this type?

By on 5/7/2010 4:18 PM ()

How was I know know about the needed "when 'Key : comparison" portion of this type?

Excellent question, and I have no good answer; neither the docs

[link:msdn.microsoft.com]

nor the hover-tooltips in VS

(don't have a screenshot hand)

are particularly useful. I'll file a bug.

By on 5/7/2010 4:43 PM ()

Argh. the < has been eaten, again.

By on 5/7/2010 4:22 PM ()

note that the "when 'Key:comparison" is the key bit

see e.g. [link:lorgonblog.spaces.live.com]

By on 5/7/2010 3:34 PM ()
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