Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow type expressions to 'locally open' modules #9484

@austindd

Description

@austindd

Currently, OCaml allows value expressions to "locally open" modules, but it would be helpful to extend this feature for use in type expressions.

For example, take the following code:

module Abc = struct
    type a
    type b
    type c
end
type abc_group = (Abc.a * Abc.b * Abc.c)

I would like to be able to define abc_group with syntax similar to this:

type abc_group = let open Abc in (a * b * c)

This would drastically reduce the verbosity of complex type signatures, especially those involving nested modules. Used in a reasonable way, this could lead to more readable code.

As for the specific syntax, I lack the experience to know what makes the most sense, so I leave that discussion to those who know more about OCaml syntax.

Edit:
@aantron proposed the following syntax:

type abc_group = Abc.(a * b * c)

This syntax is less verbose, and probably less confusing to most people.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions