Skip to content

Atom/Variant which is just underscore is a Syntax Error #97

@AeroNotix

Description

@AeroNotix

Hi,

I'm trying to convert some code which uses the underscore atom: '_', in this case I'm trying to convert some cowboy_router code. It uses '_' to mean match any host.

I understand that in OCaml a variant cannot be just named underscore:

; ocaml
        OCaml version 4.11.1

# `_;;
Error: Syntax error

Is there a workaround? There is a pretty well-established convention in Erlang code to use the underscore atom to generally mean 'match anything'. See, cowboy_router and ets matching, for example.

I know I could try, for example, binary_to_atom but that feels quite odd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions