24

Reading sources of Array2D module, I've stumbled upon this interesting construct in implementation of many core functions, for example:

[<CompiledName("Get")>]
let get (array: 'T[,]) (n:int) (m:int) =  (# "ldelem.multi 2 !0" type ('T) array n m : 'T #)  

I can only assume that this is the syntax to inline CIL and is used here obviously to gain performance benefits. However, when I've tried to use this syntax in my program, I get an error:

warning FS0042: This construct is deprecated: it is only for use in the F# library

What exactly is this? Is there any detailed documentation?

MisterMetaphor
  • 5,900
  • 3
  • 24
  • 31

2 Answers2

23

I think that this has 2 purposes:

  1. These functions compile down to exactly 1 CIL instruction which has to be encoded somewhere, so encoding at the source seems best.
  2. It allows for some extra trickery with defining polymorphic Add functions in a high performance way which is hard with the F# type system.

You can actually use this but you have to specify the --compiling-fslib (undocumented) and --standalone flags in your code.

John Palmer
  • 25,356
  • 3
  • 48
  • 67
  • 1
    Great! Where did you find about those compiler options? – MisterMetaphor Apr 12 '13 at 16:21
  • 1
    @e-i-s - There is a source file which has them all somewhere - not quite sure where though - searching the source for `standalone` will probably help – John Palmer Apr 12 '13 at 21:49
  • This answer doesn't explain why some VS2019 IntelliSense inferred type signatures have `(#a -> unit) * float * SomeType list)` - apologies if I'm missing something I should infer from the answer. – John Zabroski Sep 30 '19 at 19:23
  • I think I figured it out - #a is a Flexible Type - accepts any subtype of a. – John Zabroski Sep 30 '19 at 20:23
9

I've found some details in usenet archives: http://osdir.com/ml/lang.fsharp.general/2008-01/msg00009.html

Embedded IL in F# codes. Is this feature officially supported

Not really. The 99.9% purpose of this feature is for operations defined in FSharp.Core.dll (called fslib.dll in 1.9.2.9 and before).

Historically it has been useful to allow end-users to embed IL in order to access .NET IL functionality not accessible by F# library or language constructs using their own embedded IL. The need for this is becoming much more rare, indeed almost non-existent, now that the F# library has matured a bit more. We expect this to continue to be the case. It's even possible that we will make this a library-only feature in the "product" version of F#, though we have not yet made a final decision in this regard.

This was a message from Don Syme, dated January of 2008.

MisterMetaphor
  • 5,900
  • 3
  • 24
  • 31
  • This answer doesn't explain why some VS2019 IntelliSense inferred type signatures have `(#a -> unit) * float * SomeType list)` - apologies if I'm missing something I should infer from the answer. – John Zabroski Sep 30 '19 at 19:23
  • I think I figured it out - #a is a Flexible Type - accepts any subtype of a. – John Zabroski Sep 30 '19 at 20:23