FSharp.UMX icon indicating copy to clipboard operation
FSharp.UMX copied to clipboard

Using UMX in literal values

Open piaste opened this issue 5 years ago • 1 comments

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>)

piaste avatar Oct 18 '19 11:10 piaste

I don't believe this is possible at all.

eiriktsarpalis avatar Oct 18 '19 17:10 eiriktsarpalis