Verse has a special construct that can be used to get the type of an arbitrary expression (similar to decltype
in modern C++): type. It can be used anywhere a type can be used. For example,
Foo() : int = 0
Bar(X : type{Foo()}) : type{Foo()} = X
It is particularly useful to describe the types of functions, and it is required to give the result type of a function as another function with non-default effects. For example,
comparison := enum:
LT
EQ
GT
Less(X : int, Y : int)<decides> : int =
X < Y
Equal(X : t, Y:comparable where t:subtype(comparable))<decides> : t =
X = Y
Greater(X : int, Y : int)<decides> : int =
X > Y
Comparison(Arg : comparison) : type{_(:int, :int)<decides> : int} =
case (Arg):
comparison.LT => Less
comparison.EQ => Equal
comparison.GT => Greater
Here, the comparison function converts a comparison enumeration to the comparison operation each particular enumeration value corresponds to. This example also makes use of the special _
identifier, which can be used in type
in places where an identifier is expected without having to actually provide a name that is otherwise unused.