FSharp.UMX
FSharp.UMX copied to clipboard
Using UMX in literal values
Is it possible to create a non-numeric UMX value explicitly, without going through %
, so that it will be a valid constant expression?
I need them to be a literal so they can be used as arguments to an attribute, like this:
[<Measure>] type private Role
type RoleName = string<Role>
type RequireRoleAttribute([<ParamArray>] roles : RoleName[]) =
inherit AuthorizeAttribute(Roles = String.concat "," (Array.map (~%) roles))
module AccountRoles =
// syntax error
let Admin : RoleName = "admin"<Role>
// not a constant expression (after the operator is defined)
let [<Literal>] Admin : RoleName = "admin" * 1<Role>
// not a constant expression
let [<Literal>] Admin : RoleName = ("admin" : FSharp.UMX.string<Role>)
I don't believe this is possible at all.