Have you tried adding the 'TResult annotation at the top of your class definition ?

1
type 'TResult DesktopSearchQuery = class (* ... *) end

Hope this helps.

By on 7/22/2007 11:56 PM ()

Well I actually just want the Execute method to have a type parameter, not the class itself, so I dont want to add the declaration at the class level.

I did just try it though, and I got an explicit compilation error (as opposed to the more subtle error I got earier that sounded more like a bug in the compiler).

Thanks for the suggestion though; I guess I just need to dig deeper in to the documention. 'Expert F#' can't come out soon enough!

-John

By on 7/23/2007 3:01 AM ()

Hi John,
I think you're right - this looks like a compiler bug to me. I tried to reproduce it using the simplest possible case and the following code gives exactly the same error:

1
2
3
4
5
6
type ITest<'r> =
  abstract Foo<'t> : 't -> 't
  
type Test() = 
  interface ITest<int> with
    member x.Foo<'t>(v:'t) : 't = v

The F# team monitors this website, though it is usually better to report a bug like this directly to the fsbugs (at) microsoft (dot) com, so I would recommend sending them an email with these two examples, to make sure that it will be fixed in the future release.

(BTW: my code uses the #light syntax which makes writing many OO stuff easier in F# - the ITest is inferred to be an interface because it has only abstract methods and the Test type is using an implicit constructor syntax, so the type will have one parameterless constructor).

By on 7/24/2007 9:21 AM ()

Thanks for the comments. I'll report the bug to the F# team; I didnt want to do it before I got some confirmation that I wasn't doing anything silly...

And you're right...the #light styntax is much cleaner. Thanks for the tip.

By on 7/24/2007 5:15 PM ()

Bug already recorded - thanks - I've been following the thread.

The bug only occurs when a class type attempts to implement an interface with a generic method. You can however use an object expression to implement such an interface, e.g.

1
2
3
4
5
6
7
8
9
10
11
12
 

#light

type ITest<'r> =
  abstract Foo<'t> : 't -> 't

let Test() = 
  { new ITest<int> with
     member x.Foo(v) = v }

Thi will usually give you a workaround.

Kind regards

don

By on 7/24/2007 5:23 PM ()

Oh, here's the object expression version with an explicit type annotation at the implementation.

1
2
3
4
5
6
7
8
#light

type ITest<'r> =
  abstract Foo<'t> : 't -> 't

let Test() = 
  { new ITest<int> with
     member x.Foo<'u>(v:'u) = v }
By on 7/24/2007 5:24 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