FSI version: 11.0.50727.1
So I was working on an F# shell script and I ran across something that sort of surprised me.
When I did this:
#if INTERACTIVE
#r "System.Data.dll"
#r "FSharp.Data.TypeProviders.dll"
#r "System.Data.Linq.dll"
#endif
open System
I got an FS0010 error when I pasted the block into the FSI. But if I did not indent the #r
lines, no FS0010 error. I'm just sort of surprised that preprocessor lines would be indentation sensitive. Is this a compiler issue or is there something else at work here?
I think the specification and documentation are quite unclear on this topic, but the specification makes a notable distinction between lexical preprocessor directives and compiler directives (see §12.4):
Compiler directives are declarations in non-nested modules or namespace declaration groups in the following form:
# id string ... string
The lexical preprocessor directives
#if
,#else
,#endif
and#indent "off"
are similar to compiler directives. For details on#if
,#else
,#endif
, see §3.3. The#indent "off"
directive is described in §18.4.
My interpretation is that lexical preprocessor directives are actually hanled by some pre-processor before running the main compilation and so the indentation does not matter for these.
On the other hand, directives like #r
, #load
, #time
etc. are processed later by the compiler and so they need to match the usual F# indentation guidelines.
As @unwind says, the documentation states "Indentation is not significant for preprocessor directives", but I think this applies only to the preprocessor directives listed on that documentation page (which are lexical preprocessor directives and not compiler directives).
According to the documentation, it must be something else at work:
Indentation is not significant for preprocessor directives.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With