Thank you gneverov. Your explanation of inlines in the linked post really helps. Since this is kinda "undocumented" feature to me, I am wondering where to obtain such knowledge. Are these things inherited from OCaml?

By on 3/17/2008 7:14 AM ()

Your intuition is correct: it is both a type constraint and a function invocation. There is some discussion about inline functions and compile-time type constaints here. Typically these constructs are only used by the F# libraries.

By on 3/16/2008 4:42 AM ()
1
2
3
4
5
6
7
type foo() = 
  static member run() = print_any 5 ;;

let inline run (x:^a) = (^a: (static member run: unit -> unit)(())) ;; //no warning

run (new foo()) ;; // will not work

Is this limited to operators ? Or is there another reason why it fails ?

Discarding the static keyword (in order to try using the constraint with non-static members) will fail (i.e. the definition won't be accepted). Is it limited to static members ?

Thank you very much !

By on 3/16/2008 8:34 AM ()

It is not limited to operators. The inline function run does not use the argument x. This is an unconventional use of the feature that is confusing the compiler and, as it would seem, exposing a bug. So this works

1
2
3
4
5
6
type foo() = 
    static member run(x:foo) = print_any 5 

let inline run (x:^a) = (^a: (static member run: ^a -> unit)(x))  //no warning

run (new foo()) // will work

It is not limited to static members. The syntax for instance members is to explicitly pass the 'this' parameter as a tupled argument.

1
2
3
4
5
6
type foo() = 
    member y.bar(x:foo) = print_any 5 

let inline bar (x:^a) (y:^a) = (^a: (member bar: ^a -> unit)(x,y))

bar (new foo())

Once again there are issues if ^a doesn't appear in the signature of the member.

By on 3/16/2008 4:55 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