Skip to content

Having flag attributes is cumbersome with current API #404

@panglesd

Description

@panglesd

With current API, one needs to create an "empty payload" pattern:

let p = Ast_pattern.(pstr nil)

then register the attribute with a unit continuation:

let attr = Attribute.declare name context p ()

And finally, when getting it, turn the unit option type into a bool type:

match Attribute.get attr x with
    | Some () -> true
    | None -> false

All of this could be simplified with the following API addition:

val declare_flag : string -> 'a Context.t -> ('a, unit) t
val has_flag : ('a, unit) t -> ?mark_as_seen:bool -> 'a -> bool

(reported by @sim642 in ocaml-ppx/ppx_deriving#263 (comment))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions