Opened 4 years ago

#219 new enhancement

Forall Typedef

Reported by: ajbeach Owned by:
Priority: minor Component: cfa-cc
Version: 1.0 Keywords:


This adds (useful) forall clauses to typedefs. An example:

forall(dtype T)
typedef T & ref;

void ?{}(ref(some_struct) this) {
    // ...

This is not a particularly useful example but should illustrate the feature.

Let's start at the result. ref is just a typedefed name like any other except that it is followed by a forall argument list. Now ref takes exactly one argument, because it had one forall argument in its definition, but two or more should also be supported.

We get this by putting a forall clause on the typedef. The forall clause should contain one or more polymorphic parameter declarations (likely no assertions). For consistency with other declarations the forall should be allowed before the typedef instead of just before the type (as a type qualifier).

Assertions are meaningless on a forall typedef. Because this is just an alias all assertions are drawn from the type being aliased. Similarly otype (and likely ftype) is meaningless. ttype is not because of its list nature. However there are a couple of choices on how these meaningless items are used.

The other proposed syntax was forall(dtype T) typedef T & ref(T); which adds the parameters at the end. This isn't needed but might be clearer.

Meaningless items in the forall clause could be forbidden (so using an otype is an error), ignored (but allowed as an informal documentation) or checked (must match the underlying type's requirements).

This isn't a particularly impressive feature but it can be useful (as typedef itself is) and it seems like the most natural thing for this syntax to do.

Change History (0)

Note: See TracTickets for help on using tickets.