Skip to content

Using UMX in literal values #15

@piaste

Description

@piaste

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions