Skip to content

Ast_pattern: augment API with ebool, pbool helper, and a new map. #399

@panglesd

Description

@panglesd

estring, echar, efloat, ... helpers are created using functions generated from the constant type.

However, this type does not contain boolean constants, such as true and false. Indeed, such constants are defined as constructors (without argument, nor uppercase), as seen using utop -dparsetree:

utop # true ;;
Ptop_def
  [
    structure_item (//toplevel//[1,0+0]..[1,0+4])
      Pstr_eval
      expression (//toplevel//[1,0+0]..[1,0+4])
        Pexp_construct "true" (//toplevel//[1,0+0]..[1,0+4])
        None
  ]

As a consequence, ebool was not added to the Ast_pattern API, even though it is useful (as illustrated here)

It would be useful to have such values in the API:

val ebool : (bool, 'a, 'b) t -> (expression, 'a, 'b) t
val pbool : (bool, 'a, 'b) t -> (pattern, 'a, 'b) t

While looking at this, I noticed that we are also missing two maps:

val map_value : f:('a -> 'b) -> ('b, 'c, 'd) t -> ('a, 'c, 'd) t
val map_value' : f:(location -> 'a -> 'b) -> ('b, 'c, 'd) t -> ('a, 'c, 'd) t

with which it is simple to generate ebool and pbool, and that should be added to the API as well!

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