Skip to content

Allow name representations other than String #39

@ocecaco

Description

@ocecaco

The current representation of names is based on a String and a disambiguating integer.

data Name a = Fn String !Integer    -- free names
            | Bn !Integer !Integer  -- bound names / binding level + pattern index

Perhaps it would make sense to make names generic, such that other representations of the name (using Text, for instance), can be used. This would also allow things like attaching additional information to names (e.g., free variables might be tagged with their type).

I would propose a datatype like the following:

data Name f a = Fn f !Integer
              | Bn !Integer !Integer

This is roughly the way I have (manually) implemented binding code in some of my own projects. I also tend to have a separate data type for free variables, which removes the need to check whether a name is a free variable in places where only free variables are expected (for example, a typing context typically does not hold any bound variables), like so:

data Name f a = Name f !Integer

data Var f a = Fn (Name f a)
             | Bn !Integer !Integer

I'm not actually that familiar with the design constraints of unbound-generics, and there might be considerations that make the use of this representation undesirable. I would be happy to hear any thoughts on this, and would also be willing to spend some time to implement this change.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions