The ways in which global as pseudo-namespace can be used are murky:
When used with a DU you cannot specify the type name
When used with record fields, it doesn't work at all
Repro steps
Use of global with DU fields:
This works (susprisingly so, but I do see some logic in allowing this):
type MyDU = X of string
module Test =
let useGlobalPrefix = global.X "foo" // succeeds
This does not (but should):
type MyDU = X of string
module Test =
let useGlobalPrefix = global.MyDU.X "foo" // fails
The above should work on the grounds that MyDU.X "foo" is valid syntax, and in the root namespace, meaning I should be able to prefix it with global.
Use of global with record fields
Using global never works when used with record fields.
type MyRec = { A : string }
module Test =
let useGlobalPrefix1 = { global.MyRec.A = "foo" } // fails
let useGlobalPrefix2 = { global.A = "foo" } // fails
Expected behavior
Use of global should be accepted as it is there to be able to distinguish conflicting qualified names through their full path. Whether or not I put the above code in a namespace, it fails when prefixed with global and used on a field.
Actual behavior
It shows an error which tells me what I should do with global, but I actually already did:
error FS1126: 'global' may only be used as the first name in a qualified path
Known workarounds
Use type aliases: the problem does not happen is you alias a type with global as the prefix.
The ways in which
global
as pseudo-namespace can be used are murky:Repro steps
Use of
global
with DU fields:This works (susprisingly so, but I do see some logic in allowing this):
This does not (but should):
The above should work on the grounds that
MyDU.X "foo"
is valid syntax, and in the root namespace, meaning I should be able to prefix it withglobal
.Use of
global
with record fieldsUsing
global
never works when used with record fields.Expected behavior
Use of
global
should be accepted as it is there to be able to distinguish conflicting qualified names through their full path. Whether or not I put the above code in a namespace, it fails when prefixed withglobal
and used on a field.Actual behavior
It shows an error which tells me what I should do with
global
, but I actually already did:Known workarounds
Use type aliases: the problem does not happen is you alias a type with
global
as the prefix.